mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 14:22:37 +01:00
etcd: add SequenceKey function
This commit is contained in:
parent
d576184fdb
commit
ee9d6f21bd
2 changed files with 41 additions and 0 deletions
|
@ -130,3 +130,10 @@ func ValueKey(key string, buckets ...string) string {
|
|||
|
||||
return string(makeValueKey(bucket, []byte(key)))
|
||||
}
|
||||
|
||||
// SequenceKey is a helper function used in tests or external tools to create a
|
||||
// sequence key from the passed bucket list.
|
||||
func SequenceKey(buckets ...string) string {
|
||||
id := makeBucketID([]byte(BucketKey(buckets...)))
|
||||
return string(makeSequenceKey(id[:]))
|
||||
}
|
||||
|
|
34
kvdb/etcd/bucket_test.go
Normal file
34
kvdb/etcd/bucket_test.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
//go:build kvdb_etcd
|
||||
// +build kvdb_etcd
|
||||
|
||||
package etcd
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestBucketKey tests that a key for a bucket can be created correctly.
|
||||
func TestBucketKey(t *testing.T) {
|
||||
rootID := sha256.Sum256([]byte("@"))
|
||||
key := append(rootID[:], []byte("foo")...)
|
||||
key = append(key, 0xff)
|
||||
require.Equal(t, string(key), BucketKey("foo"))
|
||||
}
|
||||
|
||||
// TestBucketVal tests that a key for a bucket value can be created correctly.
|
||||
func TestBucketVal(t *testing.T) {
|
||||
rootID := sha256.Sum256([]byte("@"))
|
||||
key := append(rootID[:], []byte("foo")...)
|
||||
key = append(key, 0xff)
|
||||
|
||||
keyID := sha256.Sum256(key)
|
||||
require.Equal(t, string(keyID[:]), BucketVal("foo"))
|
||||
}
|
||||
|
||||
// TestSequenceKey tests that a key for a sequence can be created correctly.
|
||||
func TestSequenceKey(t *testing.T) {
|
||||
require.Contains(t, SequenceKey("foo", "bar", "baz"), "$seq$")
|
||||
}
|
Loading…
Add table
Reference in a new issue