2020-11-17 13:37:19 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-06-25 15:01:12 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-11-17 13:37:19 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-02-28 18:27:38 +00:00
|
|
|
func TestPrefixLimit(t *testing.T) {
|
2020-11-17 13:37:19 +00:00
|
|
|
unchanged := ObjectKey("unchanged")
|
2021-02-28 18:27:38 +00:00
|
|
|
_ = prefixLimit(unchanged)
|
2020-11-17 13:37:19 +00:00
|
|
|
require.Equal(t, ObjectKey("unchanged"), unchanged)
|
|
|
|
|
|
|
|
tests := []struct{ in, exp ObjectKey }{
|
|
|
|
{"", ""},
|
|
|
|
{"a", "b"},
|
|
|
|
{"\xF1", "\xF2"},
|
2021-02-28 18:27:38 +00:00
|
|
|
{"\xFF", "\xFF\x00"},
|
2020-11-17 13:37:19 +00:00
|
|
|
}
|
|
|
|
for _, test := range tests {
|
2021-02-28 18:27:38 +00:00
|
|
|
require.Equal(t, test.exp, prefixLimit(test.in))
|
2020-11-17 13:37:19 +00:00
|
|
|
if test.in != "" {
|
|
|
|
require.True(t, lessKey(test.in, test.exp))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-25 15:01:12 +01:00
|
|
|
|
|
|
|
func TestFirstIterateCursor(t *testing.T) {
|
|
|
|
afterDelimiter := ObjectKey('/' + 1)
|
|
|
|
|
|
|
|
assert.Equal(t,
|
|
|
|
iterateCursor{Key: "a"},
|
|
|
|
firstIterateCursor(false, IterateCursor{Key: "a"}, ""))
|
|
|
|
|
|
|
|
assert.Equal(t,
|
|
|
|
iterateCursor{Key: "a" + afterDelimiter, Version: -1, Inclusive: true},
|
|
|
|
firstIterateCursor(false, IterateCursor{Key: "a/"}, ""))
|
|
|
|
|
|
|
|
assert.Equal(t,
|
|
|
|
iterateCursor{Key: "a" + afterDelimiter, Version: -1, Inclusive: true},
|
|
|
|
firstIterateCursor(false, IterateCursor{Key: "a/x/y"}, ""))
|
|
|
|
|
|
|
|
assert.Equal(t,
|
|
|
|
iterateCursor{Key: "a/x/y"},
|
|
|
|
firstIterateCursor(false, IterateCursor{Key: "a/x/y"}, "a/x/"))
|
|
|
|
|
|
|
|
assert.Equal(t,
|
|
|
|
iterateCursor{Key: "2017/05/08" + afterDelimiter, Version: -1, Inclusive: true},
|
|
|
|
firstIterateCursor(false, IterateCursor{Key: "2017/05/08/"}, "2017/05/"))
|
|
|
|
|
|
|
|
assert.Equal(t,
|
|
|
|
iterateCursor{Key: "2017/05/08" + afterDelimiter, Version: -1, Inclusive: true},
|
|
|
|
firstIterateCursor(false, IterateCursor{Key: "2017/05/08/x/y"}, "2017/05/"))
|
|
|
|
}
|