|
| 1 | +package rego |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "testing" |
| 6 | + "testing/fstest" |
| 7 | + |
| 8 | + "github.com/open-policy-agent/opa/v1/storage" |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | +) |
| 12 | + |
| 13 | +func TestInitStore(t *testing.T) { |
| 14 | + fsys := fstest.MapFS{ |
| 15 | + "test1.yml": &fstest.MapFile{Data: []byte("foo: 1")}, |
| 16 | + "test2.yaml": &fstest.MapFile{Data: []byte("bar: 2")}, |
| 17 | + "test3.json": &fstest.MapFile{Data: []byte(`{"baz": 3}`)}, |
| 18 | + "dir/test4.yaml": &fstest.MapFile{Data: []byte("qux: 4")}, |
| 19 | + } |
| 20 | + store, err := initStore(fsys, []string{"."}, []string{"builtin.aws.test", "user.test"}) |
| 21 | + require.NoError(t, err) |
| 22 | + |
| 23 | + tx, err := store.NewTransaction(t.Context()) |
| 24 | + require.NoError(t, err) |
| 25 | + doc, err := store.Read(t.Context(), tx, storage.MustParsePath("/")) |
| 26 | + require.NoError(t, err) |
| 27 | + |
| 28 | + expected := map[string]any{ |
| 29 | + "foo": json.Number("1"), |
| 30 | + "bar": json.Number("2"), |
| 31 | + "baz": json.Number("3"), |
| 32 | + "qux": json.Number("4"), |
| 33 | + "namespaces": []any{"builtin.aws.test", "user.test"}, |
| 34 | + } |
| 35 | + assert.Equal(t, expected, doc) |
| 36 | +} |
0 commit comments