(c client, m *namespaceTestManager)
| 18 | ) |
| 19 | |
| 20 | func runCases(c client, m *namespaceTestManager) func(*testing.T) { |
| 21 | return func(t *testing.T) { |
| 22 | c.waitUntilLive(t) |
| 23 | |
| 24 | t.Run("case=list namespaces", func(t *testing.T) { |
| 25 | first := namespace.Namespace{Name: "my namespace"} |
| 26 | second := namespace.Namespace{Name: "my other namespace"} |
| 27 | m.add(t, &first, &second) |
| 28 | |
| 29 | resp := c.queryNamespaces(t) |
| 30 | assert.GreaterOrEqual(t, len(resp.Namespaces), 2) |
| 31 | assertNamespacesContains(t, resp.Namespaces, "my namespace") |
| 32 | assertNamespacesContains(t, resp.Namespaces, "my other namespace") |
| 33 | }) |
| 34 | |
| 35 | t.Run("case=gets empty namespace", func(t *testing.T) { |
| 36 | n := &namespace.Namespace{Name: t.Name()} |
| 37 | m.add(t, n) |
| 38 | |
| 39 | resp := c.queryTuple(t, &ketoapi.RelationQuery{Namespace: &n.Name}) |
| 40 | assert.Len(t, resp.RelationTuples, 0) |
| 41 | }) |
| 42 | |
| 43 | t.Run("case=creates tuple and uses it then", func(t *testing.T) { |
| 44 | n := &namespace.Namespace{Name: t.Name()} |
| 45 | m.add(t, n) |
| 46 | |
| 47 | tuple := &ketoapi.RelationTuple{ |
| 48 | Namespace: n.Name, |
| 49 | Object: fmt.Sprintf("object for client %T", c), |
| 50 | Relation: "access", |
| 51 | SubjectID: new("client"), |
| 52 | } |
| 53 | |
| 54 | c.createTuple(t, tuple) |
| 55 | |
| 56 | resp := c.queryTuple(t, &ketoapi.RelationQuery{Namespace: &tuple.Namespace}) |
| 57 | require.Len(t, resp.RelationTuples, 1) |
| 58 | assert.Equal(t, tuple, resp.RelationTuples[0]) |
| 59 | |
| 60 | // try the check API to see whether the tuple is interpreted correctly |
| 61 | assert.True(t, c.check(t, tuple)) |
| 62 | batchResult := c.batchCheck(t, []*ketoapi.RelationTuple{tuple}) |
| 63 | require.Len(t, batchResult, 1) |
| 64 | assert.True(t, batchResult[0].allowed) |
| 65 | assert.Empty(t, batchResult[0].errorMessage) |
| 66 | }) |
| 67 | |
| 68 | t.Run("case=creates tuple with empty IDs", func(t *testing.T) { |
| 69 | n := &namespace.Namespace{Name: t.Name()} |
| 70 | m.add(t, n) |
| 71 | |
| 72 | tuples := []*ketoapi.RelationTuple{{ |
| 73 | Namespace: n.Name, |
| 74 | Object: "", |
| 75 | Relation: "access", |
| 76 | SubjectID: new(""), |
| 77 | }, { |
no test coverage detected