mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
storage: add reversion test
This commit is contained in:
parent
05228729a3
commit
74fbf9d6a7
39
storage/reversion_test.go
Normal file
39
storage/reversion_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestReversion tests that reversion could be encoded to and decoded from
|
||||
// bytes slice. Moreover, the lexicograph order of its byte slice representation
|
||||
// follows the order of (main, sub).
|
||||
func TestReversion(t *testing.T) {
|
||||
tests := []reversion{
|
||||
// order in (main, sub)
|
||||
reversion{},
|
||||
reversion{main: 1, sub: 0},
|
||||
reversion{main: 1, sub: 1},
|
||||
reversion{main: 2, sub: 0},
|
||||
reversion{main: math.MaxInt64, sub: math.MaxInt64},
|
||||
}
|
||||
|
||||
bs := make([][]byte, len(tests))
|
||||
for i, tt := range tests {
|
||||
b := newRevBytes()
|
||||
revToBytes(tt, b)
|
||||
bs[i] = b
|
||||
|
||||
if grev := bytesToRev(b); !reflect.DeepEqual(grev, tt) {
|
||||
t.Errorf("#%d: reversion = %+v, want %+v", i, grev, tt)
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < len(tests)-1; i++ {
|
||||
if bytes.Compare(bs[i], bs[i+1]) >= 0 {
|
||||
t.Errorf("#%d: %v (%+v) should be smaller than %v (%+v)", i, bs[i], tests[i], bs[i+1], tests[i+1])
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user