(t *testing.T)
| 52 | } |
| 53 | |
| 54 | func TestBuildInsert(t *testing.T) { |
| 55 | t.Parallel() |
| 56 | nid := uuidx.NewV4() |
| 57 | |
| 58 | q, args, err := buildInsert(time.Now(), nid, nil) |
| 59 | assert.Error(t, err) |
| 60 | assert.Empty(t, q) |
| 61 | assert.Empty(t, args) |
| 62 | |
| 63 | obj1, obj2, sub1, obj3 := uuidx.NewV4(), uuidx.NewV4(), uuidx.NewV4(), uuidx.NewV4() |
| 64 | |
| 65 | now := time.Now() |
| 66 | |
| 67 | q, args, err = buildInsert(now, nid, []*relationtuple.RelationTuple{ |
| 68 | { |
| 69 | Namespace: "ns1", |
| 70 | Object: obj1, |
| 71 | Relation: "rel1", |
| 72 | Subject: &relationtuple.SubjectID{ |
| 73 | ID: sub1, |
| 74 | }, |
| 75 | }, |
| 76 | { |
| 77 | Namespace: "ns2", |
| 78 | Object: obj2, |
| 79 | Relation: "rel2", |
| 80 | Subject: &relationtuple.SubjectSet{ |
| 81 | Namespace: "ns3", |
| 82 | Object: obj3, |
| 83 | Relation: "rel3", |
| 84 | }, |
| 85 | }, |
| 86 | }) |
| 87 | require.NoError(t, err) |
| 88 | |
| 89 | assert.Equal(t, q, "INSERT INTO keto_relation_tuples (shard_id, nid, namespace, object, relation, subject_id, subject_set_namespace, subject_set_object, subject_set_relation, commit_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") |
| 90 | assert.Equal(t, []any{ |
| 91 | args[0], // this is kind of cheating but we generate the shard id in the buildInsert function |
| 92 | nid, |
| 93 | "ns1", |
| 94 | obj1, |
| 95 | "rel1", |
| 96 | uuid.NullUUID{UUID: sub1, Valid: true}, |
| 97 | sql.NullString{}, uuid.NullUUID{}, sql.NullString{}, |
| 98 | now, |
| 99 | |
| 100 | args[10], // again, cheating |
| 101 | nid, |
| 102 | "ns2", |
| 103 | obj2, |
| 104 | "rel2", |
| 105 | uuid.NullUUID{}, |
| 106 | sql.NullString{String: "ns3", Valid: true}, uuid.NullUUID{UUID: obj3, Valid: true}, sql.NullString{String: "rel3", Valid: true}, |
| 107 | now, |
| 108 | }, args) |
| 109 | } |
| 110 | |
| 111 | func TestBuildInsertUUIDs(t *testing.T) { |
nothing calls this directly
no test coverage detected