-
Notifications
You must be signed in to change notification settings - Fork 168
/
read_assertions.go
53 lines (45 loc) · 1.51 KB
/
read_assertions.go
1
2
3
4
5
6
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package test
import (
"context"
"testing"
"github.com/openfga/openfga/pkg/logger"
"github.com/openfga/openfga/pkg/server/commands"
"github.com/openfga/openfga/pkg/storage"
"github.com/openfga/openfga/pkg/testutils"
"github.com/stretchr/testify/require"
openfgapb "go.buf.build/openfga/go/openfga/api/openfga/v1"
)
func TestReadAssertionQuery(t *testing.T, datastore storage.OpenFGADatastore) {
type readAssertionsQueryTest struct {
_name string
request *openfgapb.ReadAssertionsRequest
expectedResponse *openfgapb.ReadAssertionsResponse
expectedError error
}
var tests = []readAssertionsQueryTest{
{
_name: "ReturnsAssertionModelNotFound",
request: &openfgapb.ReadAssertionsRequest{StoreId: "store", AuthorizationModelId: "test"},
expectedResponse: &openfgapb.ReadAssertionsResponse{
AuthorizationModelId: "test",
Assertions: []*openfgapb.Assertion{},
},
},
}
ctx := context.Background()
logger := logger.NewNoopLogger()
for _, test := range tests {
t.Run(test._name, func(t *testing.T) {
store := testutils.CreateRandomString(10)
query := commands.NewReadAssertionsQuery(datastore, logger)
test.request.StoreId = store
actualResponse, actualError := query.Execute(ctx, test.request.StoreId, test.request.AuthorizationModelId)
if test.expectedError != nil {
require.ErrorIs(t, actualError, test.expectedError)
} else {
require.NoError(t, actualError)
require.Equal(t, test.expectedResponse, actualResponse)
}
})
}
}