From 3326529445b86623757b2477abb74975a4978bde Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Thu, 24 Oct 2019 17:02:17 +0000 Subject: [PATCH] Fix instance migrate test self link comparisons Signed-off-by: Modular Magician --- .../resource_compute_instance_migrate_test.go | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/google/resource_compute_instance_migrate_test.go b/google/resource_compute_instance_migrate_test.go index f3f4e6a9973..1d0a0ef5f67 100644 --- a/google/resource_compute_instance_migrate_test.go +++ b/google/resource_compute_instance_migrate_test.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "strings" "testing" "google.golang.org/api/compute/v1" @@ -863,18 +864,38 @@ func runInstanceMigrateTest(t *testing.T, id, testName string, version int, attr } for k, v := range expected { - if attributes[k] != v { - t.Fatalf( - "bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", - testName, k, expected[k], k, attributes[k], attributes) + // source is the only self link, so compare by relpaths if source is being + // compared + if strings.HasSuffix(k, "source") { + if !compareSelfLinkOrResourceName("", attributes[k], v, nil) && attributes[k] != v { + t.Fatalf( + "bad uri: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", + testName, k, expected[k], k, attributes[k], attributes) + } + } else { + if attributes[k] != v { + t.Fatalf( + "bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", + testName, k, expected[k], k, attributes[k], attributes) + } } } for k, v := range attributes { - if expected[k] != v { - t.Fatalf( - "bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", - testName, k, expected[k], k, attributes[k], attributes) + // source is the only self link, so compare by relpaths if source is being + // compared + if strings.HasSuffix(k, "source") { + if !compareSelfLinkOrResourceName("", expected[k], v, nil) && expected[k] != v { + t.Fatalf( + "bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", + testName, k, expected[k], k, attributes[k], expected) + } + } else { + if expected[k] != v { + t.Fatalf( + "bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", + testName, k, expected[k], k, attributes[k], expected) + } } } }