blob: a43aaf49b3788de7a13210df43dc3071e9ae75ab [file] [log] [blame]
package shortcut2
import (
"bytes"
"encoding/json"
"sort"
"testing"
"github.com/stretchr/testify/assert"
"go.skia.org/infra/go/ds"
"go.skia.org/infra/go/ds/testutil"
"go.skia.org/infra/go/testutils/unittest"
)
func TestShortcut(t *testing.T) {
unittest.LargeTest(t)
cleanup := testutil.InitDatastore(t, ds.SHORTCUT)
defer cleanup()
// Write a shortcut.
sh := &Shortcut{
Keys: []string{
"https://foo",
"https://bar",
"https://baz",
},
}
b, err := json.Marshal(sh)
buf := bytes.NewBuffer(b)
id, err := Insert(buf)
assert.NoError(t, err)
assert.NotEqual(t, "", id)
// Read it back, confirm it is unchanged, except for being sorted.
sh2, err := Get(id)
assert.NoError(t, err)
assert.NotEqual(t, sh, sh2)
sort.Strings(sh.Keys)
assert.Equal(t, sh, sh2)
}