Skip to content

Commit

Permalink
refactor builtin test, use single engine instance
Browse files Browse the repository at this point in the history
  • Loading branch information
gertd committed Apr 11, 2024
1 parent a9e8549 commit 342fa69
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 72 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ require (
github.com/alecthomas/kong v0.9.0
github.com/aserto-dev/aserto-grpc v0.2.2
github.com/aserto-dev/aserto-management v0.9.4
github.com/aserto-dev/azm v0.1.6
github.com/aserto-dev/azm v0.1.8
github.com/aserto-dev/certs v0.0.6
github.com/aserto-dev/clui v0.8.3
github.com/aserto-dev/errors v0.0.7
github.com/aserto-dev/go-aserto v0.31.2
github.com/aserto-dev/go-aserto v0.31.3-0.20240411011658-eecfb593dc54
github.com/aserto-dev/go-authorizer v0.20.5
github.com/aserto-dev/go-directory v0.31.3
github.com/aserto-dev/go-directory-cli v0.31.1
github.com/aserto-dev/go-edge-ds v0.31.3
github.com/aserto-dev/go-edge-ds v0.31.4
github.com/aserto-dev/go-grpc v0.8.63
github.com/aserto-dev/go-topaz-ui v0.1.4
github.com/aserto-dev/header v0.0.7
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ github.com/aserto-dev/aserto-grpc v0.2.2 h1:i6rWdvydyqs7eBqsZHYdPPCC+xVwQve8KrBg
github.com/aserto-dev/aserto-grpc v0.2.2/go.mod h1:uDMB5njLdoCa0Hr+TOg6A4gH85uNqTvufkM5sKtEjcE=
github.com/aserto-dev/aserto-management v0.9.4 h1:GiBWkTwn2mgvbS3ftsmro2RS0oiORjlNzLsY9Q5j0vQ=
github.com/aserto-dev/aserto-management v0.9.4/go.mod h1:gc2e123PnLdDrVv6H9r3sl8yU5qegAwR3aAwXcmaBJM=
github.com/aserto-dev/azm v0.1.6 h1:6Ou+/rqOINJzbd2ziyt/GdkuFr2ZKrncHRk5emFOgN4=
github.com/aserto-dev/azm v0.1.6/go.mod h1:qWp/M1EXpyLnqHBgwgYoE390XONvgSpOT3XSmQWN2nM=
github.com/aserto-dev/azm v0.1.8 h1:NDhTCUoumEfbMd+Dg/KkW+vgXgoo9ESOQTJ8Lr15qKg=
github.com/aserto-dev/azm v0.1.8/go.mod h1:q9hcNvUbhvy3JvGYOwRq/UT8JKRFBV2aA/3UtcQunzg=
github.com/aserto-dev/certs v0.0.6 h1:V79JptXMvgePJ2rgktu8QdgbEQsIXxF1kXqQhPM76NI=
github.com/aserto-dev/certs v0.0.6/go.mod h1:ppJ/GVSerB8EsikJeQP71LJBuHiUW2avS2f84oC/75c=
github.com/aserto-dev/clui v0.8.3 h1:foEJuVpMFVP4La3SxUcinxRLOZx/TyS2BRuahbywYFg=
Expand All @@ -431,6 +431,8 @@ github.com/aserto-dev/errors v0.0.7 h1:pBn9RhP2iiDl30oAWsf8aLxvt4yCpLKZOCJRIaeRM
github.com/aserto-dev/errors v0.0.7/go.mod h1:wiQ68oKTyAQVAv+SvB5GyuAD6PewalA/D6Fq30gNUbQ=
github.com/aserto-dev/go-aserto v0.31.2 h1:5kr8RskTmb3Zlto+oYmu5GMX6AwDLSlxgBtMNhEH8aA=
github.com/aserto-dev/go-aserto v0.31.2/go.mod h1:zxuHxDIyfdS/Kc11ESiUbcAitCQxxJt4PVIlFbAZgiA=
github.com/aserto-dev/go-aserto v0.31.3-0.20240411011658-eecfb593dc54 h1:1aUBDiZuk8n0ZWfnAntqE42V9ae7kRqMqe/AqTjs5KY=
github.com/aserto-dev/go-aserto v0.31.3-0.20240411011658-eecfb593dc54/go.mod h1:6mW3wUC62a8TbqYH64lq350MBj+W3WwtlxXNZRybbOY=
github.com/aserto-dev/go-authorizer v0.20.5 h1:ne5EvWO8Yqs7lMgZom7nGuGNMP5TOftHu0rS7ws1HSw=
github.com/aserto-dev/go-authorizer v0.20.5/go.mod h1:cwuPKELMmzTwLMYYoIKFwtf9psNYsDXefOGywtTm094=
github.com/aserto-dev/go-decision-logs v0.0.4 h1:beu/mhqZ92ovhSIPOv2f4q0Ci7HWNLla/j/x+ZD5eHw=
Expand All @@ -439,8 +441,8 @@ github.com/aserto-dev/go-directory v0.31.3 h1:Twiulwykm+ivko+H73TMVSvSlE2urIN3Xi
github.com/aserto-dev/go-directory v0.31.3/go.mod h1:Pjb9QcswMnuIPl8iDexG4d2AcFtLWDpVisGodrKuvC0=
github.com/aserto-dev/go-directory-cli v0.31.1 h1:bajldwElZHcCisBIP6QE0VI9VbxCrhm2SW4wQnAWIrY=
github.com/aserto-dev/go-directory-cli v0.31.1/go.mod h1:lTFABO1yjQjCLXeMW4Zq2wnfKj6o8XAY+1w95gnM6lI=
github.com/aserto-dev/go-edge-ds v0.31.3 h1:ZNdrseEKZqKczhMiHC/3/JnP84VhAxnsF1EX7a4VpFc=
github.com/aserto-dev/go-edge-ds v0.31.3/go.mod h1:Hlf+j9Zz/gX10MyPJdvxUr6phREsEQLn+eFLVLzv6uU=
github.com/aserto-dev/go-edge-ds v0.31.4 h1:+s+Z+FAMvGnJXjq2/TNl2vWX4yz7+rhdVVB/7viQhg0=
github.com/aserto-dev/go-edge-ds v0.31.4/go.mod h1:C3zwIfM4LyQM2OXIQYlfZF8Zy6H/UHluQHilxFEXgTk=
github.com/aserto-dev/go-grpc v0.8.63 h1:/8t5JSWb7nR1uF3SUuxZxt/mvhz+9mI5juZLP06wElU=
github.com/aserto-dev/go-grpc v0.8.63/go.mod h1:ZAlsa2ooMcXuEWhUvAsrANm6lpMHFKJsIEhvpqydn+Y=
github.com/aserto-dev/go-http-metrics v0.10.1-20221024-1 h1:nONd24V5nyJ0IIw8QE+OKv30YuHOTNbJ4FsvczLaM8o=
Expand Down
118 changes: 54 additions & 64 deletions pkg/app/tests/builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,59 @@ import (
"github.com/stretchr/testify/require"
)

var builtinHelptests = []struct {
func TestBuiltins(t *testing.T) {
harness := atesting.SetupOnline(t, func(cfg *config.Config) {
cfg.Edge.DBPath = atesting.AssetAcmeDBFilePath()
})
t.Cleanup(harness.Cleanup)

client := harness.CreateGRPCClient()

ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

// BuiltinHelptests(ctx, client)
for _, tc := range BuiltinHelpTests {
f := func(t *testing.T) {
resp, err := client.Query(ctx, &authz2.QueryRequest{
Query: tc.query,
})
require.NoError(t, err)
require.NotNil(t, resp)
require.NotNil(t, resp.Response)

r := resp.Response.AsMap()

v1 := r["result"].([]interface{})
v2 := v1[0].(map[string]interface{})
v3 := v2["bindings"].(map[string]interface{})
v := v3["x"]

assert.Equal(t, v, tc.expected)
}

t.Run(tc.name, f)
}

// BuiltinNotFoundErrTests
for _, tc := range BuiltinNotFoundErrTests {
f := func(t *testing.T) {
resp, err := client.Query(ctx, &authz2.QueryRequest{
Query: tc.query,
})
require.NoError(t, err)
require.NotNil(t, resp)
require.NotNil(t, resp.Response)

r := resp.Response.AsMap()
require.NotNil(t, r)
}

t.Run(tc.name, f)
}
}

var BuiltinHelpTests = []struct {
name string
query string
expected map[string]interface{}
Expand Down Expand Up @@ -132,41 +184,7 @@ var builtinHelptests = []struct {
},
}

func TestBuiltinsHelp(t *testing.T) {
harness := atesting.SetupOnline(t, func(cfg *config.Config) {
cfg.Edge.DBPath = atesting.AssetAcmeDBFilePath()
})
t.Cleanup(harness.Cleanup)

client := harness.CreateGRPCClient()

ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

for _, tc := range builtinHelptests {
f := func(t *testing.T) {
resp, err := client.Query(ctx, &authz2.QueryRequest{
Query: tc.query,
})
require.NoError(t, err)
require.NotNil(t, resp)
require.NotNil(t, resp.Response)

r := resp.Response.AsMap()

v1 := r["result"].([]interface{})
v2 := v1[0].(map[string]interface{})
v3 := v2["bindings"].(map[string]interface{})
v := v3["x"]

assert.Equal(t, v, tc.expected)
}

t.Run(tc.name, f)
}
}

var builtinNotFoundErrTests = []struct {
var BuiltinNotFoundErrTests = []struct {
name string
query string
expected map[string]interface{}
Expand Down Expand Up @@ -205,31 +223,3 @@ var builtinNotFoundErrTests = []struct {
})`,
},
}

func TestBuiltinsNotFoundErr(t *testing.T) {
harness := atesting.SetupOnline(t, func(cfg *config.Config) {
cfg.Edge.DBPath = atesting.AssetAcmeDBFilePath()
})
defer harness.Cleanup()

client := harness.CreateGRPCClient()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

for _, tc := range builtinNotFoundErrTests {
f := func(t *testing.T) {
resp, err := client.Query(ctx, &authz2.QueryRequest{
Query: tc.query,
})
require.NoError(t, err)
require.NotNil(t, resp)
require.NotNil(t, resp.Response)

r := resp.Response.AsMap()
require.NotNil(t, r)
}

t.Run(tc.name, f)
}
}
2 changes: 1 addition & 1 deletion pkg/testing/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (h *EngineHarness) CreateGRPCClient() authz2.AuthorizerClient {

opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(&tlsConf)))

conn, err := grpc.Dial("127.0.0.1:8282", opts...)
conn, err := grpc.NewClient("127.0.0.1:8282", opts...)
if err != nil {
h.t.Fatal(err)
}
Expand Down

0 comments on commit 342fa69

Please sign in to comment.