...

Source file src/go.etcd.io/etcd/server/v3/mvcc/revision_test.go

Documentation: go.etcd.io/etcd/server/v3/mvcc

     1  // Copyright 2015 The etcd Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package mvcc
    16  
    17  import (
    18  	"bytes"
    19  	"math"
    20  	"reflect"
    21  	"testing"
    22  )
    23  
    24  // TestRevision tests that revision could be encoded to and decoded from
    25  // bytes slice. Moreover, the lexicographical order of its byte slice representation
    26  // follows the order of (main, sub).
    27  func TestRevision(t *testing.T) {
    28  	tests := []revision{
    29  		// order in (main, sub)
    30  		{},
    31  		{main: 1, sub: 0},
    32  		{main: 1, sub: 1},
    33  		{main: 2, sub: 0},
    34  		{main: math.MaxInt64, sub: math.MaxInt64},
    35  	}
    36  
    37  	bs := make([][]byte, len(tests))
    38  	for i, tt := range tests {
    39  		b := newRevBytes()
    40  		revToBytes(tt, b)
    41  		bs[i] = b
    42  
    43  		if grev := bytesToRev(b); !reflect.DeepEqual(grev, tt) {
    44  			t.Errorf("#%d: revision = %+v, want %+v", i, grev, tt)
    45  		}
    46  	}
    47  
    48  	for i := 0; i < len(tests)-1; i++ {
    49  		if bytes.Compare(bs[i], bs[i+1]) >= 0 {
    50  			t.Errorf("#%d: %v (%+v) should be smaller than %v (%+v)", i, bs[i], tests[i], bs[i+1], tests[i+1])
    51  		}
    52  	}
    53  }
    54  

View as plain text