From d94011e8007c70c7b94c8a185828b2380208c5e0 Mon Sep 17 00:00:00 2001 From: Eric Solender Date: Fri, 3 Jun 2022 13:58:56 -0400 Subject: [PATCH] added sanity check in remove rels function --- save.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/save.go b/save.go index 5275611..9eb6559 100644 --- a/save.go +++ b/save.go @@ -266,11 +266,13 @@ func removeRelations(transaction neo4j.Transaction, dels map[int64][]int64) erro var params []interface{} + expectedDels := 0 for id, ids := range dels { params = append(params, map[string]interface{}{ "startNodeId": id, "endNodeIds": ids, }) + expectedDels += len(ids) } cyq, err := dsl.QB(). @@ -299,8 +301,17 @@ func removeRelations(transaction neo4j.Transaction, dels map[int64][]int64) erro } else if err = res.Err(); err != nil { return fmt.Errorf("%s: %w", err.Error(), ErrInternal) } - //todo sanity check to make sure the affects worked + summary, err := res.Consume() + if err != nil { + return fmt.Errorf("failed to consume result summary, %s: %w", err.Error(), ErrInternal) + } + + actualRelsDeleted := summary.Counters().RelationshipsDeleted() + if expectedDels != actualRelsDeleted { + return fmt.Errorf("expected relationship deletions not equal to actual. Expected=%v|Actual=%v", expectedDels, actualRelsDeleted) + } + return nil }