From a58d588150c7035e0eeb87fa665ba316cfeceb27 Mon Sep 17 00:00:00 2001 From: Aaron L <aaron@bettercoder.net> Date: Sun, 18 Sep 2016 17:19:37 -0700 Subject: [PATCH] Fix small error message in tests - Ensure we check foreign key values with reload AFTER we do all our relationship struct checks, reloading kills the relationship struct. --- templates_test/relationship_to_one_setops.tpl | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/templates_test/relationship_to_one_setops.tpl b/templates_test/relationship_to_one_setops.tpl index db5c87c..5ca642e 100644 --- a/templates_test/relationship_to_one_setops.tpl +++ b/templates_test/relationship_to_one_setops.tpl @@ -38,6 +38,20 @@ func test{{$txt.LocalTable.NameGo}}ToOneSetOp{{$txt.ForeignTable.NameGo}}_{{$txt t.Fatal(err) } + if a.R.{{$txt.Function.Name}} != x { + t.Error("relationship struct not set to correct value") + } + + {{if .Unique -}} + if x.R.{{$txt.Function.ForeignName}} != &a { + t.Error("failed to append to foreign relationship struct") + } + {{else -}} + if x.R.{{$txt.Function.ForeignName}}[0] != &a { + t.Error("failed to append to foreign relationship struct") + } + {{end -}} + {{if $txt.Function.UsesBytes -}} if 0 != bytes.Compare(a.{{$txt.Function.LocalAssignment}}, x.{{$txt.Function.ForeignAssignment}}) { {{else -}} @@ -45,9 +59,6 @@ func test{{$txt.LocalTable.NameGo}}ToOneSetOp{{$txt.ForeignTable.NameGo}}_{{$txt {{end -}} t.Error("foreign key was wrong value", a.{{$txt.Function.LocalAssignment}}) } - if a.R.{{$txt.Function.Name}} != x { - t.Error("relationship struct not set to correct value") - } zero := reflect.Zero(reflect.TypeOf(a.{{$txt.Function.LocalAssignment}})) reflect.Indirect(reflect.ValueOf(&a.{{$txt.Function.LocalAssignment}})).Set(zero) @@ -63,16 +74,6 @@ func test{{$txt.LocalTable.NameGo}}ToOneSetOp{{$txt.ForeignTable.NameGo}}_{{$txt {{end -}} t.Error("foreign key was wrong value", a.{{$txt.Function.LocalAssignment}}, x.{{$txt.Function.ForeignAssignment}}) } - - {{if .Unique -}} - if x.R.{{$txt.Function.ForeignName}} != &a { - t.Error("failed to append to foreign relationship struct") - } - {{else -}} - if x.R.{{$txt.Function.ForeignName}}[0] != &a { - t.Error("failed to append to foreign relationship struct") - } - {{end -}} } } {{- if .Nullable}} @@ -119,7 +120,7 @@ func test{{$txt.LocalTable.NameGo}}ToOneRemoveOp{{$txt.ForeignTable.NameGo}}_{{$ } if a.{{$txt.LocalTable.ColumnNameGo}}.Valid { - t.Error("R struct entry should be nil") + t.Error("foreign key value should be nil") } {{if .Unique -}}