func TextExistence()

in dstester/dstester.go [280:321]


func TextExistence(t *testing.T, items []Resource) {
	t.Logf("Testing for existence of GCP resources")
	testsExists := map[string]struct {
		input Resource
		want  string
	}{}
	for _, v := range items {
		if v.Expected == "" {
			v.Expected = v.Name
		}

		testsExists[fmt.Sprintf("Test %s %s exists", v.Product, v.Name)] = struct {
			input Resource
			want  string
		}{v, v.Expected}
	}

	for name, tc := range testsExists {
		t.Run(name, func(t *testing.T) {
			got, err := tc.input.Exists()
			if err != nil {
				debug := strings.ReplaceAll(tc.input.existsString(), gcloud, "gcloud")
				if strings.Contains(err.Error(), "was not found") {
					t.Fatalf("expected item to exist, it did not\n To debug:\n %s", debug)
				}

				t.Fatalf("expected no error, got: '%v' To debug:\n %s", err, debug)
			}

			if !reflect.DeepEqual(tc.want, got) {
				// artifact registry call leaks stuff into stderr
				if strings.Contains(got, "Repository Size") {
					if strings.Contains(got, tc.want) {
						return
					}
				}

				t.Fatalf("expected: '%v', got: '%v'", tc.want, got)
			}
		})
	}
}