-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for determining consistency
This commit adds tests for determineConsistency. Signed-off-by: John Schaeffer <[email protected]>
- Loading branch information
1 parent
534a7bf
commit a65d212
Showing
2 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package query | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.infratographer.com/permissions-api/internal/testingx" | ||
"go.infratographer.com/permissions-api/internal/types" | ||
"go.infratographer.com/x/gidx" | ||
) | ||
|
||
func TestConsistency(t *testing.T) { | ||
namespace := "testconsistency" | ||
ctx := context.Background() | ||
e := testEngine(ctx, t, namespace) | ||
|
||
tenantID, err := gidx.NewID("tnntten") | ||
require.NoError(t, err) | ||
tenantRes, err := e.NewResourceFromID(tenantID) | ||
require.NoError(t, err) | ||
|
||
parentID, err := gidx.NewID("tnntten") | ||
require.NoError(t, err) | ||
parentRes, err := e.NewResourceFromID(parentID) | ||
require.NoError(t, err) | ||
|
||
otherID, err := gidx.NewID("tnntten") | ||
require.NoError(t, err) | ||
otherRes, err := e.NewResourceFromID(otherID) | ||
require.NoError(t, err) | ||
|
||
testCases := []testingx.TestCase[types.Resource, string]{ | ||
{ | ||
Name: "WithZedToken", | ||
Input: tenantRes, | ||
SetupFn: func(ctx context.Context, t *testing.T) context.Context { | ||
rels := []types.Relationship{ | ||
{ | ||
Resource: tenantRes, | ||
Relation: "parent", | ||
Subject: parentRes, | ||
}, | ||
} | ||
|
||
err := e.CreateRelationships(ctx, rels) | ||
|
||
require.NoError(t, err) | ||
|
||
return ctx | ||
}, | ||
CheckFn: func(ctx context.Context, t *testing.T, res testingx.TestResult[string]) { | ||
assert.NoError(t, res.Err) | ||
assert.Equal(t, consistencyAtLeastAsFresh, res.Success) | ||
}, | ||
}, | ||
{ | ||
Name: "WithoutZedToken", | ||
Input: otherRes, | ||
CheckFn: func(ctx context.Context, t *testing.T, res testingx.TestResult[string]) { | ||
assert.NoError(t, res.Err) | ||
assert.Equal(t, consistencyMinimizeLatency, res.Success) | ||
}, | ||
}, | ||
} | ||
|
||
testFn := func(ctx context.Context, res types.Resource) testingx.TestResult[string] { | ||
_, consistencyName := e.determineConsistency(ctx, res) | ||
|
||
out := testingx.TestResult[string]{ | ||
Success: consistencyName, | ||
} | ||
|
||
return out | ||
} | ||
|
||
testingx.RunTests(ctx, t, testCases, testFn) | ||
} |