go-mmkv/vault_test.go

27 lines
468 B
Go
Raw Normal View History

2022-12-04 22:27:41 +00:00
package mmkv
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_loadVault(t *testing.T) {
file, err := os.Open("./testdata/mmkv.default")
require.NoError(t, err)
v, err := loadVault(file, nil)
require.NoError(t, err)
assert.Equal(t, 2, len(v.Keys()))
2022-12-04 23:14:32 +00:00
val, err := v.GetString("world")
assert.Equal(t, "hello", val)
assert.NoError(t, err)
2022-12-04 22:27:41 +00:00
2022-12-04 23:14:32 +00:00
_, err = v.GetBytes("foo")
assert.Error(t, err)
2022-12-04 22:27:41 +00:00
}