...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package testutils
16
17 import (
18 "flag"
19 "io/ioutil"
20 "testing"
21
22 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test"
23
24 "github.com/google/go-cmp/cmp"
25 )
26
27 var update = flag.Bool("update", false, "update .golden files")
28
29 func VerifyContentsMatch(t *testing.T, actualBytes []byte, expectedFilePath string) {
30 if *update {
31 ioutil.WriteFile(expectedFilePath, actualBytes, 0644)
32 }
33 expectedBytes, err := ioutil.ReadFile(expectedFilePath)
34 if err != nil {
35 t.Fatalf("error reading file '%v': %v", expectedFilePath, err)
36 }
37 expectedBytes = []byte(test.TrimLicenseHeaderFromYaml(string(expectedBytes)))
38 diff := cmp.Diff(actualBytes, expectedBytes)
39 if diff != "" {
40 t.Logf("actual value:\n%v", string(actualBytes))
41 t.Logf("expected value:\n%v", string(expectedBytes))
42 t.Logf("actual value does not match expected value in '%v'", expectedFilePath)
43 t.Fatalf("diff: %v", diff)
44 }
45 }
46
View as plain text