diff --git a/kyaml/copyutil/copyutil_test.go b/kyaml/copyutil/copyutil_test.go index 59a25635c..7f364b1f4 100644 --- a/kyaml/copyutil/copyutil_test.go +++ b/kyaml/copyutil/copyutil_test.go @@ -4,6 +4,7 @@ package copyutil_test import ( + "fmt" "io/ioutil" "os" "path/filepath" @@ -104,7 +105,9 @@ func TestDiff_srcDestContentsDiffer(t *testing.T) { diff, err := Diff(s, d) assert.NoError(t, err) - assert.ElementsMatch(t, diff.List(), []string{"a1/f.yaml"}) + assert.ElementsMatch(t, diff.List(), []string{ + fmt.Sprintf("a1%sf.yaml", string(filepath.Separator)), + }) } // TestDiff_srcDestContentsDifferInDirs verifies if identical files @@ -130,7 +133,11 @@ func TestDiff_srcDestContentsDifferInDirs(t *testing.T) { diff, err := Diff(s, d) assert.NoError(t, err) assert.ElementsMatch(t, diff.List(), []string{ - "a1", "a1/f.yaml", "b1/f.yaml", "b1"}) + "a1", + fmt.Sprintf("a1%sf.yaml", string(filepath.Separator)), + fmt.Sprintf("b1%sf.yaml", string(filepath.Separator)), + "b1", + }) } // TestDiff_skipGitSrc verifies that .git directories in the source diff --git a/kyaml/kio/pkgio_reader_test.go b/kyaml/kio/pkgio_reader_test.go index 7ee12c862..74cef9dad 100644 --- a/kyaml/kio/pkgio_reader_test.go +++ b/kyaml/kio/pkgio_reader_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -269,15 +270,15 @@ func TestLocalPackageReader_Read_nestedDirs(t *testing.T) { metadata: annotations: config.kubernetes.io/index: '0' - config.kubernetes.io/package: 'a/b' - config.kubernetes.io/path: 'a/b/a_test.yaml' + config.kubernetes.io/package: 'a${SEP}b' + config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' `, `c: d # second metadata: annotations: config.kubernetes.io/index: '1' - config.kubernetes.io/package: 'a/b' - config.kubernetes.io/path: 'a/b/a_test.yaml' + config.kubernetes.io/package: 'a${SEP}b' + config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' `, `# second thing e: f @@ -288,8 +289,8 @@ g: metadata: annotations: config.kubernetes.io/index: '0' - config.kubernetes.io/package: 'a/b' - config.kubernetes.io/path: 'a/b/b_test.yaml' + config.kubernetes.io/package: 'a${SEP}b' + config.kubernetes.io/path: 'a${SEP}b${SEP}b_test.yaml' `, } for i := range nodes { @@ -297,7 +298,8 @@ metadata: if !assert.NoError(t, err) { return } - if !assert.Equal(t, expected[i], val) { + want := strings.ReplaceAll(expected[i], "${SEP}", string(filepath.Separator)) + if !assert.Equal(t, want, val) { return } } @@ -321,25 +323,29 @@ func TestLocalPackageReader_Read_matchRegex(t *testing.T) { assert.FailNow(t, "wrong number items") } - val, err := nodes[0].String() - assert.NoError(t, err) - assert.Equal(t, `a: b #first + expected := []string{ + `a: b #first metadata: annotations: config.kubernetes.io/index: '0' - config.kubernetes.io/package: 'a/b' - config.kubernetes.io/path: 'a/b/a_test.yaml' -`, val) - - val, err = nodes[1].String() - assert.NoError(t, err) - assert.Equal(t, `c: d # second + config.kubernetes.io/package: 'a${SEP}b' + config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' +`, + `c: d # second metadata: annotations: config.kubernetes.io/index: '1' - config.kubernetes.io/package: 'a/b' - config.kubernetes.io/path: 'a/b/a_test.yaml' -`, val) + config.kubernetes.io/package: 'a${SEP}b' + config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' +`, + } + + for i, node := range nodes { + val, err := node.String() + assert.NoError(t, err) + want := strings.ReplaceAll(expected[i], "${SEP}", string(filepath.Separator)) + assert.Equal(t, want, val) + } } func TestLocalPackageReader_Read_skipSubpackage(t *testing.T) { @@ -360,25 +366,29 @@ func TestLocalPackageReader_Read_skipSubpackage(t *testing.T) { assert.FailNow(t, "wrong number items") } - val, err := nodes[0].String() - assert.NoError(t, err) - assert.Equal(t, `a: b #first + expected := []string{ + `a: b #first metadata: annotations: config.kubernetes.io/index: '0' - config.kubernetes.io/package: 'a/b' - config.kubernetes.io/path: 'a/b/a_test.yaml' -`, val) - - val, err = nodes[1].String() - assert.NoError(t, err) - assert.Equal(t, `c: d # second + config.kubernetes.io/package: 'a${SEP}b' + config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' +`, + `c: d # second metadata: annotations: config.kubernetes.io/index: '1' - config.kubernetes.io/package: 'a/b' - config.kubernetes.io/path: 'a/b/a_test.yaml' -`, val) + config.kubernetes.io/package: 'a${SEP}b' + config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' +`, + } + + for i, node := range nodes { + val, err := node.String() + assert.NoError(t, err) + want := strings.ReplaceAll(expected[i], "${SEP}", string(filepath.Separator)) + assert.Equal(t, want, val) + } } func TestLocalPackageReader_Read_includeSubpackage(t *testing.T) { @@ -398,29 +408,23 @@ func TestLocalPackageReader_Read_includeSubpackage(t *testing.T) { if !assert.Len(t, nodes, 3) { assert.FailNow(t, "wrong number items") } - val, err := nodes[0].String() - assert.NoError(t, err) - assert.Equal(t, `a: b #first + + expected := []string{ + `a: b #first metadata: annotations: config.kubernetes.io/index: '0' - config.kubernetes.io/package: 'a/b' - config.kubernetes.io/path: 'a/b/a_test.yaml' -`, val) - - val, err = nodes[1].String() - assert.NoError(t, err) - assert.Equal(t, `c: d # second + config.kubernetes.io/package: 'a${SEP}b' + config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' +`, + `c: d # second metadata: annotations: config.kubernetes.io/index: '1' - config.kubernetes.io/package: 'a/b' - config.kubernetes.io/path: 'a/b/a_test.yaml' -`, val) - - val, err = nodes[2].String() - assert.NoError(t, err) - assert.Equal(t, `# second thing + config.kubernetes.io/package: 'a${SEP}b' + config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' +`, + `# second thing e: f g: h: @@ -429,9 +433,17 @@ g: metadata: annotations: config.kubernetes.io/index: '0' - config.kubernetes.io/package: 'a/c' - config.kubernetes.io/path: 'a/c/c_test.yaml' -`, val) + config.kubernetes.io/package: 'a${SEP}c' + config.kubernetes.io/path: 'a${SEP}c${SEP}c_test.yaml' +`, + } + + for i, node := range nodes { + val, err := node.String() + assert.NoError(t, err) + want := strings.ReplaceAll(expected[i], "${SEP}", string(filepath.Separator)) + assert.Equal(t, want, val) + } } // func TestLocalPackageReaderWriter_DeleteFiles(t *testing.T) {