(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestBuildDelete(t *testing.T) { |
| 17 | t.Parallel() |
| 18 | nid := uuidx.NewV4() |
| 19 | |
| 20 | q, args, err := buildDelete(nid, nil) |
| 21 | assert.Error(t, err) |
| 22 | assert.Empty(t, q) |
| 23 | assert.Empty(t, args) |
| 24 | |
| 25 | obj1, obj2, sub1, obj3 := uuidx.NewV4(), uuidx.NewV4(), uuidx.NewV4(), uuidx.NewV4() |
| 26 | |
| 27 | q, args, err = buildDelete(nid, []*relationtuple.RelationTuple{ |
| 28 | { |
| 29 | Namespace: "ns1", |
| 30 | Object: obj1, |
| 31 | Relation: "rel1", |
| 32 | Subject: &relationtuple.SubjectID{ |
| 33 | ID: sub1, |
| 34 | }, |
| 35 | }, |
| 36 | { |
| 37 | Namespace: "ns2", |
| 38 | Object: obj2, |
| 39 | Relation: "rel2", |
| 40 | Subject: &relationtuple.SubjectSet{ |
| 41 | Namespace: "ns3", |
| 42 | Object: obj3, |
| 43 | Relation: "rel3", |
| 44 | }, |
| 45 | }, |
| 46 | }) |
| 47 | require.NoError(t, err) |
| 48 | |
| 49 | // parentheses are important here |
| 50 | assert.Equal(t, q, "DELETE FROM keto_relation_tuples WHERE ((namespace = ? AND object = ? AND relation = ? AND subject_id = ? AND subject_set_namespace IS NULL AND subject_set_object IS NULL AND subject_set_relation IS NULL) OR (namespace = ? AND object = ? AND relation = ? AND subject_id IS NULL AND subject_set_namespace = ? AND subject_set_object = ? AND subject_set_relation = ?)) AND nid = ?") |
| 51 | assert.Equal(t, []any{"ns1", obj1, "rel1", sub1, "ns2", obj2, "rel2", "ns3", obj3, "rel3", nid}, args) |
| 52 | } |
| 53 | |
| 54 | func TestBuildInsert(t *testing.T) { |
| 55 | t.Parallel() |
nothing calls this directly
no test coverage detected