Skip to content

Commit

Permalink
Group test helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
annasong20 committed Jan 5, 2023
1 parent 599d24c commit 1f14895
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions api/krusty/localizer/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,52 @@ func setWorkingDir(t *testing.T, workingDir string) {
require.NoError(t, err)
}

func link(t *testing.T, testDir filesys.ConfirmedDir, links map[string]string) {
t.Helper()

for newLink, file := range links {
require.NoError(t, os.Symlink(testDir.Join(file), testDir.Join(newLink)))
}
}

func simplePathAndFiles(t *testing.T) (locPath string, files map[string]string) {
t.Helper()

locPath = filepath.Join(LocalizeDir, "github.com",
"kubernetes-sigs", "kustomize", "kustomize", "v4.5.7",
"api", "krusty", "testdata", "localize", "simple")
files = map[string]string{
"kustomization.yaml": simpleKustomization,
"deployment.yaml": simpleDeployment,
"service.yaml": simpleService,
}
return
}

func remotePathAndFiles(t *testing.T) (locPath string, files map[string]string) {
t.Helper()

locPath = filepath.Join(LocalizeDir, "github.com",
"kubernetes-sigs", "kustomize", "master",
"api", "krusty", "testdata", "localize", "remote")
simplePath, simpleFiles := simplePathAndFiles(t)
files = map[string]string{
"kustomization.yaml": fmt.Sprintf(`apiVersion: kustomize.config.k8s.io/v1beta1
commonLabels:
purpose: remoteReference
kind: Kustomization
resources:
- %s
- hpa.yaml
`, simplePath),
"hpa.yaml": remoteHPA,
}
for path, content := range simpleFiles {
files[filepath.Join(simplePath, path)] = content
}
return
}

// checkFs checks fsActual, the real file system, against fsExpected, a file system in memory, for contents
// in directory walkDir. checkFs does not allow symlinks.
func checkFs(t *testing.T, walkDir string, fsExpected filesys.FileSystem, fsActual filesys.FileSystem) {
Expand Down Expand Up @@ -299,14 +345,6 @@ func TestWorkingDir(t *testing.T) {
checkFs(t, dst, fsExpected, fsActual)
}

func link(t *testing.T, testDir filesys.ConfirmedDir, links map[string]string) {
t.Helper()

for newLink, file := range links {
require.NoError(t, os.Symlink(testDir.Join(file), testDir.Join(newLink)))
}
}

func TestSymlinks(t *testing.T) {
// test directory
// - link to target
Expand Down Expand Up @@ -353,20 +391,6 @@ func TestSymlinks(t *testing.T) {
checkFs(t, dst, fsExpected, fsActual)
}

func simplePathAndFiles(t *testing.T) (locPath string, files map[string]string) {
t.Helper()

locPath = filepath.Join(LocalizeDir, "github.com",
"kubernetes-sigs", "kustomize", "kustomize", "v4.5.7",
"api", "krusty", "testdata", "localize", "simple")
files = map[string]string{
"kustomization.yaml": simpleKustomization,
"deployment.yaml": simpleDeployment,
"service.yaml": simpleService,
}
return
}

func TestRemoteTargetDefaultDst(t *testing.T) {
fsExpected, fsActual, testDir := prepareFs(t, nil, nil)
setWorkingDir(t, testDir.String())
Expand Down Expand Up @@ -468,30 +492,6 @@ func TestRemoteRoot(t *testing.T) {
checkFs(t, dst, fsExpected, fsActual)
}

func remotePathAndFiles(t *testing.T) (locPath string, files map[string]string) {
t.Helper()

locPath = filepath.Join(LocalizeDir, "github.com",
"kubernetes-sigs", "kustomize", "master",
"api", "krusty", "testdata", "localize", "remote")
simplePath, simpleFiles := simplePathAndFiles(t)
files = map[string]string{
"kustomization.yaml": fmt.Sprintf(`apiVersion: kustomize.config.k8s.io/v1beta1
commonLabels:
purpose: remoteReference
kind: Kustomization
resources:
- %s
- hpa.yaml
`, simplePath),
"hpa.yaml": remoteHPA,
}
for path, content := range simpleFiles {
files[filepath.Join(simplePath, path)] = content
}
return
}

func TestNestedRemoteRoots(t *testing.T) {
fsExpected, fsActual, testDir := prepareFs(t, nil, map[string]string{
// TODO(annasong): Change the ref to the release after kustomize/v4.5.7.
Expand Down

0 comments on commit 1f14895

Please sign in to comment.