func matchOutputFile()

in config/testing/helpers.go [74:109]


func matchOutputFile(t *testing.T, actual []byte, expectedFilePath string) {
	expected, err := ioutil.ReadFile(expectedFilePath)
	if err != nil && !os.IsNotExist(err) {
		t.Fatalf("couldn't read test data: %v", err)
	}

	needsUpdate := false
	const updateEnvVar = "UPDATE_COMPONENTCONFIG_FIXTURE_DATA"

	if os.IsNotExist(err) {
		needsUpdate = true
		if os.Getenv(updateEnvVar) != "true" {
			t.Error("couldn't find test data")
		}
	} else {
		if !bytes.Equal(expected, actual) {
			t.Errorf("Output does not match expected, diff (- want, + got):\n%s\n",
				cmp.Diff(string(expected), string(actual)))
			needsUpdate = true
		}
	}
	if needsUpdate {
		if os.Getenv(updateEnvVar) == "true" {
			if err := os.MkdirAll(filepath.Dir(expectedFilePath), 0755); err != nil {
				t.Fatal(err)
			}
			if err := ioutil.WriteFile(expectedFilePath, actual, 0644); err != nil {
				t.Fatal(err)
			}
			t.Error("wrote expected test data... verify, commit, and rerun tests")
		} else {
			t.Errorf("if the diff is expected because of a new type or a new field, "+
				"re-run with %s=true to update the compatibility data or generate missing files", updateEnvVar)
		}
	}
}