key_test.go 570 Bytes
Newer Older
1 2 3 4 5
package flatfs

import (
	"testing"

tavit ohanian's avatar
tavit ohanian committed
6
	"gitlab.dms3.io/dms3/public/go-datastore"
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
)

var (
	validKeys = []string{
		"/FOO",
		"/1BAR1",
		"/=EMACS-IS-KING=",
	}
	invalidKeys = []string{
		"/foo/bar",
		`/foo\bar`,
		"/foo\000bar",
		"/=Vim-IS-KING=",
	}
)

func TestKeyIsValid(t *testing.T) {
	for _, key := range validKeys {
		k := datastore.NewKey(key)
		if !keyIsValid(k) {
			t.Errorf("expected key %s to be valid", k)
		}
	}
	for _, key := range invalidKeys {
		k := datastore.NewKey(key)
		if keyIsValid(k) {
			t.Errorf("expected key %s to be invalid", k)
		}
	}
}