mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 09:24:23 +00:00
Simplified tests with helper func
This commit is contained in:
@@ -49,32 +49,14 @@ func TestLocalPackageReader_Read_empty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLocalPackageReader_Read_pkg(t *testing.T) {
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
s := SetupDirectories(t, filepath.Join("a", "b"), filepath.Join("a", "c"))
|
||||
defer s.Clean()
|
||||
s.WriteFile(t, "a_test.yaml", readFileA)
|
||||
s.WriteFile(t, "b_test.yaml", readFileB)
|
||||
s.WriteFile(t, "c_test.yaml", readFileC)
|
||||
s.WriteFile(t, "d_test.yaml", readFileD)
|
||||
|
||||
testLocalPackageReaderReadPkg(t, "./", nil)
|
||||
testLocalPackageReaderReadPkg(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "b")))
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "c")))
|
||||
require.NoError(t, fs.WriteFile("a_test.yaml", readFileA))
|
||||
require.NoError(t, fs.WriteFile("b_test.yaml", readFileB))
|
||||
require.NoError(t, fs.WriteFile("c_test.yaml", readFileC))
|
||||
require.NoError(t, fs.WriteFile("d_test.yaml", readFileD))
|
||||
|
||||
testLocalPackageReaderReadPkg(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
func testLocalPackageReaderReadPkg(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
testOnDiskAndOnMem(t, []mockFile{
|
||||
{path: "a/b"},
|
||||
{path: "a/c"},
|
||||
{path: "a_test.yaml", content: readFileA},
|
||||
{path: "b_test.yaml", content: readFileB},
|
||||
{path: "c_test.yaml", content: readFileC},
|
||||
{path: "d_test.yaml", content: readFileD},
|
||||
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
rfr := LocalPackageReader{
|
||||
PackagePath: path,
|
||||
FileSystem: filesys.FileSystemOrOnDisk{FileSystem: mockFS},
|
||||
@@ -124,35 +106,18 @@ metadata:
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected[i], val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocalPackageReader_Read_pkgAndSkipFile(t *testing.T) {
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
s := SetupDirectories(t, filepath.Join("a", "b"), filepath.Join("a", "c"))
|
||||
defer s.Clean()
|
||||
s.WriteFile(t, "a_test.yaml", readFileA)
|
||||
s.WriteFile(t, "b_test.yaml", readFileB)
|
||||
s.WriteFile(t, "c_test.yaml", readFileC)
|
||||
s.WriteFile(t, "d_test.yaml", readFileD)
|
||||
|
||||
testLocalPackageReaderReadPkgAndSkipFile(t, "./", nil)
|
||||
testLocalPackageReaderReadPkgAndSkipFile(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "b")))
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "c")))
|
||||
require.NoError(t, fs.WriteFile("a_test.yaml", readFileA))
|
||||
require.NoError(t, fs.WriteFile("b_test.yaml", readFileB))
|
||||
require.NoError(t, fs.WriteFile("c_test.yaml", readFileC))
|
||||
require.NoError(t, fs.WriteFile("d_test.yaml", readFileD))
|
||||
|
||||
testLocalPackageReaderReadPkgAndSkipFile(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
func testLocalPackageReaderReadPkgAndSkipFile(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
testOnDiskAndOnMem(t, []mockFile{
|
||||
{path: "a/b"},
|
||||
{path: "a/c"},
|
||||
{path: "a_test.yaml", content: readFileA},
|
||||
{path: "b_test.yaml", content: readFileB},
|
||||
{path: "c_test.yaml", content: readFileC},
|
||||
{path: "d_test.yaml", content: readFileD},
|
||||
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
rfr := LocalPackageReader{
|
||||
PackagePath: path,
|
||||
FileSkipFunc: func(relPath string) bool { return relPath == "d_test.yaml" },
|
||||
@@ -197,47 +162,30 @@ metadata:
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected[i], val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocalPackageReader_Read_JSON(t *testing.T) {
|
||||
aTestJSON := []byte(`{
|
||||
testOnDiskAndOnMem(t, []mockFile{
|
||||
{path: "a/b"},
|
||||
{path: "a/c"},
|
||||
{path: "a_test.json", content: []byte(`{
|
||||
"a": "b"
|
||||
}`)
|
||||
bTestJSON := []byte(`{
|
||||
}`),
|
||||
},
|
||||
{path: "b_test.json", content: []byte(`{
|
||||
"e": "f",
|
||||
"g": {
|
||||
"h": ["i", "j"]
|
||||
}
|
||||
}`)
|
||||
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
s := SetupDirectories(t, filepath.Join("a", "b"), filepath.Join("a", "c"))
|
||||
defer s.Clean()
|
||||
|
||||
s.WriteFile(t, "a_test.json", aTestJSON)
|
||||
s.WriteFile(t, "b_test.json", bTestJSON)
|
||||
|
||||
testLocalPackageReaderReadJSON(t, "./", nil)
|
||||
testLocalPackageReaderReadJSON(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "b")))
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "c")))
|
||||
require.NoError(t, fs.WriteFile("a_test.json", aTestJSON))
|
||||
require.NoError(t, fs.WriteFile("b_test.json", bTestJSON))
|
||||
|
||||
testLocalPackageReaderReadJSON(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
func testLocalPackageReaderReadJSON(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
}`),
|
||||
},
|
||||
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
rfr := LocalPackageReader{
|
||||
PackagePath: path,
|
||||
MatchFilesGlob: []string{"*.json"},
|
||||
FileSystem: filesys.FileSystemOrOnDisk{FileSystem: mockFS},
|
||||
}
|
||||
rfr.FileSystem.Set(mockFS)
|
||||
nodes, err := rfr.Read()
|
||||
require.NoError(t, err)
|
||||
require.Len(t, nodes, 2)
|
||||
@@ -252,31 +200,16 @@ func testLocalPackageReaderReadJSON(t *testing.T, path string, mockFS filesys.Fi
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected[i], val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocalPackageReader_Read_file(t *testing.T) {
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
s := SetupDirectories(t, filepath.Join("a", "b"), filepath.Join("a", "c"))
|
||||
defer s.Clean()
|
||||
s.WriteFile(t, filepath.Join("a_test.yaml"), readFileA)
|
||||
s.WriteFile(t, filepath.Join("b_test.yaml"), readFileB)
|
||||
|
||||
testLocalPackageReaderReadFile(t, "./", nil)
|
||||
testLocalPackageReaderReadFile(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "b")))
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "c")))
|
||||
require.NoError(t, fs.WriteFile("a_test.yaml", readFileA))
|
||||
require.NoError(t, fs.WriteFile("b_test.yaml", readFileB))
|
||||
|
||||
testLocalPackageReaderReadFile(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
func testLocalPackageReaderReadFile(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
testOnDiskAndOnMem(t, []mockFile{
|
||||
{path: "a/b"},
|
||||
{path: "a/c"},
|
||||
{path: "a_test.yaml", content: readFileA},
|
||||
{path: "b_test.yaml", content: readFileB},
|
||||
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
rfr := LocalPackageReader{
|
||||
PackagePath: filepath.Join(path, "a_test.yaml"),
|
||||
FileSystem: filesys.FileSystemOrOnDisk{FileSystem: mockFS},
|
||||
@@ -303,31 +236,16 @@ metadata:
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected[i], val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocalPackageReader_Read_pkgOmitAnnotations(t *testing.T) {
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
s := SetupDirectories(t, filepath.Join("a", "b"), filepath.Join("a", "c"))
|
||||
defer s.Clean()
|
||||
s.WriteFile(t, filepath.Join("a_test.yaml"), readFileA)
|
||||
s.WriteFile(t, filepath.Join("b_test.yaml"), readFileB)
|
||||
|
||||
testLocalPackageReaderReadPkgOmitAnnotations(t, "./", nil)
|
||||
testLocalPackageReaderReadPkgOmitAnnotations(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "b")))
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "c")))
|
||||
require.NoError(t, fs.WriteFile("a_test.yaml", readFileA))
|
||||
require.NoError(t, fs.WriteFile("b_test.yaml", readFileB))
|
||||
|
||||
testLocalPackageReaderReadPkgOmitAnnotations(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
func testLocalPackageReaderReadPkgOmitAnnotations(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
testOnDiskAndOnMem(t, []mockFile{
|
||||
{path: "a/b"},
|
||||
{path: "a/c"},
|
||||
{path: "a_test.yaml", content: readFileA},
|
||||
{path: "b_test.yaml", content: readFileB},
|
||||
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
rfr := LocalPackageReader{
|
||||
PackagePath: path,
|
||||
OmitReaderAnnotations: true,
|
||||
@@ -354,31 +272,16 @@ g:
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected[i], val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocalPackageReader_Read_PreserveSeqIndent(t *testing.T) {
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
s := SetupDirectories(t, filepath.Join("a", "b"), filepath.Join("a", "c"))
|
||||
defer s.Clean()
|
||||
s.WriteFile(t, filepath.Join("a_test.yaml"), readFileA)
|
||||
s.WriteFile(t, filepath.Join("b_test.yaml"), readFileB)
|
||||
|
||||
testLocalPackageReaderReadPreserveSeqIndent(t, "./", nil)
|
||||
testLocalPackageReaderReadPreserveSeqIndent(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "b")))
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "c")))
|
||||
require.NoError(t, fs.WriteFile("a_test.yaml", readFileA))
|
||||
require.NoError(t, fs.WriteFile("b_test.yaml", readFileB))
|
||||
|
||||
testLocalPackageReaderReadPreserveSeqIndent(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
func testLocalPackageReaderReadPreserveSeqIndent(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
testOnDiskAndOnMem(t, []mockFile{
|
||||
{path: "a/b"},
|
||||
{path: "a/c"},
|
||||
{path: "a_test.yaml", content: readFileA},
|
||||
{path: "b_test.yaml", content: readFileB},
|
||||
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
rfr := LocalPackageReader{
|
||||
PackagePath: path,
|
||||
PreserveSeqIndent: true,
|
||||
@@ -420,31 +323,16 @@ metadata:
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected[i], val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocalPackageReader_Read_nestedDirs(t *testing.T) {
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
s := SetupDirectories(t, filepath.Join("a", "b"), filepath.Join("a", "c"))
|
||||
defer s.Clean()
|
||||
s.WriteFile(t, filepath.Join("a", "b", "a_test.yaml"), readFileA)
|
||||
s.WriteFile(t, filepath.Join("a", "b", "b_test.yaml"), readFileB)
|
||||
|
||||
testLocalPackageReaderReadNestedDirs(t, "./", nil)
|
||||
testLocalPackageReaderReadNestedDirs(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "b")))
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "c")))
|
||||
require.NoError(t, fs.WriteFile(filepath.Join("a", "b", "a_test.yaml"), readFileA))
|
||||
require.NoError(t, fs.WriteFile(filepath.Join("a", "b", "b_test.yaml"), readFileB))
|
||||
|
||||
testLocalPackageReaderReadNestedDirs(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
func testLocalPackageReaderReadNestedDirs(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
testOnDiskAndOnMem(t, []mockFile{
|
||||
{path: "a/b"},
|
||||
{path: "a/c"},
|
||||
{path: "a/b/a_test.yaml", content: readFileA},
|
||||
{path: "a/b/b_test.yaml", content: readFileB},
|
||||
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
rfr := LocalPackageReader{
|
||||
PackagePath: path,
|
||||
FileSystem: filesys.FileSystemOrOnDisk{FileSystem: mockFS},
|
||||
@@ -483,31 +371,16 @@ metadata:
|
||||
want := strings.ReplaceAll(expected[i], "${SEP}", string(filepath.Separator))
|
||||
require.Equal(t, want, val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocalPackageReader_Read_matchRegex(t *testing.T) {
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
s := SetupDirectories(t, filepath.Join("a", "b"), filepath.Join("a", "c"))
|
||||
defer s.Clean()
|
||||
s.WriteFile(t, filepath.Join("a", "b", "a_test.yaml"), readFileA)
|
||||
s.WriteFile(t, filepath.Join("a", "b", "b_test.yaml"), readFileB)
|
||||
|
||||
testLocalPackageReaderReadMatchRegex(t, "./", nil)
|
||||
testLocalPackageReaderReadMatchRegex(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "b")))
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "c")))
|
||||
require.NoError(t, fs.WriteFile(filepath.Join("a", "b", "a_test.yaml"), readFileA))
|
||||
require.NoError(t, fs.WriteFile(filepath.Join("a", "b", "b_test.yaml"), readFileB))
|
||||
|
||||
testLocalPackageReaderReadMatchRegex(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
func testLocalPackageReaderReadMatchRegex(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
testOnDiskAndOnMem(t, []mockFile{
|
||||
{path: "a/b"},
|
||||
{path: "a/c"},
|
||||
{path: "a/b/a_test.yaml", content: readFileA},
|
||||
{path: "a/b/b_test.yaml", content: readFileB},
|
||||
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
rfr := LocalPackageReader{
|
||||
PackagePath: path,
|
||||
MatchFilesGlob: []string{`a*.yaml`},
|
||||
@@ -538,33 +411,17 @@ metadata:
|
||||
want := strings.ReplaceAll(expected[i], "${SEP}", string(filepath.Separator))
|
||||
require.Equal(t, want, val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocalPackageReader_Read_skipSubpackage(t *testing.T) {
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
s := SetupDirectories(t, filepath.Join("a", "b"), filepath.Join("a", "c"))
|
||||
defer s.Clean()
|
||||
s.WriteFile(t, filepath.Join("a", "b", "a_test.yaml"), readFileA)
|
||||
s.WriteFile(t, filepath.Join("a", "c", "c_test.yaml"), readFileB)
|
||||
s.WriteFile(t, filepath.Join("a", "c", "pkgFile"), pkgFile)
|
||||
|
||||
testLocalPackageReaderReadSkipSubpackage(t, "./", nil)
|
||||
testLocalPackageReaderReadSkipSubpackage(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "b")))
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "c")))
|
||||
require.NoError(t, fs.WriteFile(filepath.Join("a", "b", "a_test.yaml"), readFileA))
|
||||
require.NoError(t, fs.WriteFile(filepath.Join("a", "c", "c_test.yaml"), readFileB))
|
||||
require.NoError(t, fs.WriteFile(filepath.Join("a", "c", "pkgFile"), pkgFile))
|
||||
|
||||
testLocalPackageReaderReadSkipSubpackage(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
func testLocalPackageReaderReadSkipSubpackage(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
testOnDiskAndOnMem(t, []mockFile{
|
||||
{path: "a/b"},
|
||||
{path: "a/c"},
|
||||
{path: "a/b/a_test.yaml", content: readFileA},
|
||||
{path: "a/c/c_test.yaml", content: readFileB},
|
||||
{path: "a/c/pkgFile", content: pkgFile},
|
||||
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
rfr := LocalPackageReader{
|
||||
PackagePath: path,
|
||||
PackageFileName: "pkgFile",
|
||||
@@ -595,33 +452,17 @@ metadata:
|
||||
want := strings.ReplaceAll(expected[i], "${SEP}", string(filepath.Separator))
|
||||
require.Equal(t, want, val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocalPackageReader_Read_includeSubpackage(t *testing.T) {
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
s := SetupDirectories(t, filepath.Join("a", "b"), filepath.Join("a", "c"))
|
||||
defer s.Clean()
|
||||
s.WriteFile(t, filepath.Join("a", "b", "a_test.yaml"), readFileA)
|
||||
s.WriteFile(t, filepath.Join("a", "c", "c_test.yaml"), readFileB)
|
||||
s.WriteFile(t, filepath.Join("a", "c", "pkgFile"), pkgFile)
|
||||
|
||||
testLocalPackageReaderReadIncludeSubpackage(t, "./", nil)
|
||||
testLocalPackageReaderReadIncludeSubpackage(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "b")))
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join("a", "c")))
|
||||
require.NoError(t, fs.WriteFile(filepath.Join("a", "b", "a_test.yaml"), readFileA))
|
||||
require.NoError(t, fs.WriteFile(filepath.Join("a", "c", "c_test.yaml"), readFileB))
|
||||
require.NoError(t, fs.WriteFile(filepath.Join("a", "c", "pkgFile"), pkgFile))
|
||||
|
||||
testLocalPackageReaderReadIncludeSubpackage(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
func testLocalPackageReaderReadIncludeSubpackage(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
testOnDiskAndOnMem(t, []mockFile{
|
||||
{path: "a/b"},
|
||||
{path: "a/c"},
|
||||
{path: "a/b/a_test.yaml", content: readFileA},
|
||||
{path: "a/c/c_test.yaml", content: readFileB},
|
||||
{path: "a/c/pkgFile", content: pkgFile},
|
||||
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
|
||||
rfr := LocalPackageReader{
|
||||
PackagePath: path,
|
||||
IncludeSubpackages: true,
|
||||
@@ -664,53 +505,47 @@ metadata:
|
||||
want := strings.ReplaceAll(expected[i], "${SEP}", string(filepath.Separator))
|
||||
require.Equal(t, want, val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// func TestLocalPackageReaderWriter_DeleteFiles(t *testing.T) {
|
||||
// g, _, clean := testutil.SetupDefaultRepoAndWorkspace(t)
|
||||
// defer clean()
|
||||
// if !assert.NoError(t, os.Chdir(g.RepoDirectory)) {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// rw := LocalPackageReadWriter{PackagePath: "."}
|
||||
// nodes, err := rw.Read()
|
||||
// if !assert.NoError(t, err) {
|
||||
// t.FailNow()
|
||||
// }
|
||||
// _, err = os.Stat(filepath.Join("java", "java-deployment.resource.yaml"))
|
||||
// if !assert.NoError(t, err) {
|
||||
// t.FailNow()
|
||||
// }
|
||||
//
|
||||
// // delete one of the nodes
|
||||
// var newNodes []*yaml.RNode
|
||||
// for i := range nodes {
|
||||
// meta, err := nodes[i].GetMeta()
|
||||
// if !assert.NoError(t, err) {
|
||||
// t.FailNow()
|
||||
// }
|
||||
// if meta.Name == "app" && meta.Kind == "Deployment" {
|
||||
// continue
|
||||
// }
|
||||
// newNodes = append(newNodes, nodes[i])
|
||||
// }
|
||||
//
|
||||
// if !assert.NoError(t, rw.Write(newNodes)) {
|
||||
// t.FailNow()
|
||||
// }
|
||||
//
|
||||
// _, err = os.Stat(filepath.Join("java", "java-deployment.resource.yaml"))
|
||||
// if !assert.Error(t, err) {
|
||||
// t.FailNow()
|
||||
// }
|
||||
//
|
||||
// diff, err := copyutil.Diff(filepath.Join(g.DatasetDirectory, testutil.Dataset1), ".")
|
||||
// if !assert.NoError(t, err) {
|
||||
// t.FailNow()
|
||||
// }
|
||||
//
|
||||
// assert.ElementsMatch(t,
|
||||
// diff.List(),
|
||||
// []string{filepath.Join("java", "java-deployment.resource.yaml")})
|
||||
// }
|
||||
type mockFile struct {
|
||||
path string
|
||||
// nil content implies this is a directory
|
||||
content []byte
|
||||
}
|
||||
|
||||
func testOnDiskAndOnMem(t *testing.T, files []mockFile, f func(t *testing.T, path string, fs filesys.FileSystem)) {
|
||||
t.Run("on_disk", func(t *testing.T) {
|
||||
var dirs []string
|
||||
for _, file := range files {
|
||||
if file.content == nil {
|
||||
dirs = append(dirs, filepath.FromSlash(file.path))
|
||||
}
|
||||
}
|
||||
|
||||
s := SetupDirectories(t, dirs...)
|
||||
defer s.Clean()
|
||||
for _, file := range files {
|
||||
if file.content != nil {
|
||||
s.WriteFile(t, filepath.FromSlash(file.path), file.content)
|
||||
}
|
||||
}
|
||||
|
||||
f(t, "./", nil)
|
||||
f(t, s.Root, nil)
|
||||
})
|
||||
|
||||
t.Run("on_mem", func(t *testing.T) {
|
||||
fs := filesys.MakeFsInMemory()
|
||||
for _, file := range files {
|
||||
path := filepath.FromSlash(file.path)
|
||||
if file.content == nil {
|
||||
require.NoError(t, fs.MkdirAll(path))
|
||||
} else {
|
||||
require.NoError(t, fs.WriteFile(path, file.content))
|
||||
}
|
||||
}
|
||||
|
||||
f(t, "/", fs)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user