func checkObjectProperties()

in pkg/testutil/componentsuite/validate.go [85:130]


func checkObjectProperties(t *testing.T, comp *bundle.Component, tc *TestCase) {
	objCheckMap := make(map[objKey]ObjectCheck)
	for _, oc := range tc.Expect.Objects {
		objCheckMap[objKeyFromObjCheck(oc)] = oc
	}

	objMap := make(map[objKey]string)
	for _, obj := range comp.Spec.Objects {
		key := objKeyFromObj(obj)
		t.Run(fmt.Sprintf("for object %v", obj), func(t *testing.T) {
			matchFail := false
			objStr, err := converter.FromObject(obj).ToYAMLString()
			if err != nil {
				// This is a very unlikely error.
				t.Fatal(err)
			}
			objMap[key] = objStr

			check := objCheckMap[key]
			for _, expStr := range check.FindSubstrs {
				if !strings.Contains(objStr, expStr) {
					t.Errorf("Did not find %q in object %v, but expected to", expStr, key)
					matchFail = true
				}
			}

			for _, noExpStr := range check.NotFindSubstrs {
				if strings.Contains(objStr, noExpStr) {
					t.Errorf("Found %q in object %v, but did not expect to", noExpStr, key)
					matchFail = true
				}
			}

			if matchFail {
				t.Logf("Contents for object that didn't meet expectations %v:\n%s", key, objStr)
			}

		})
	}

	for key := range objCheckMap {
		if _, ok := objMap[key]; !ok {
			t.Errorf("Got object-keys %s, but expected to find object %v", stringMapKeys(objMap), key)
		}
	}
}