Skip to content

Commit 57ebf07

Browse files
committed
Avoid recursive copy of test files
For the git tagger test, set up a dummy repo inside the testdata folder. Signed-off-by: Cornelius Weig <[email protected]>
1 parent 7d3ef15 commit 57ebf07

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

integration/build_test.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ import (
2626
"github.com/GoogleContainerTools/skaffold/integration/skaffold"
2727
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
2828
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
29-
"github.com/GoogleContainerTools/skaffold/testutil"
3029
"github.com/docker/docker/api/types"
31-
"github.com/kubernetes-sigs/kind/pkg/fs"
3230
)
3331

3432
const imageName = "simple-build:"
@@ -43,7 +41,7 @@ func TestBuild(t *testing.T) {
4341
dir string
4442
args []string
4543
expectImage string
46-
setup func(*testing.T)
44+
setup func(t *testing.T, workdir string) (teardown func())
4745
}{
4846
{
4947
description: "docker build",
@@ -79,23 +77,14 @@ func TestBuild(t *testing.T) {
7977

8078
for _, test := range tests {
8179
t.Run(test.description, func(t *testing.T) {
82-
tempDir, tearDown := testutil.NewTempDir(t)
83-
defer tearDown()
84-
err := fs.Copy(test.dir, tempDir.Root())
85-
failNowIfError(t, err)
86-
87-
origWd, _ := os.Getwd()
88-
defer func() { os.Chdir(origWd) }()
89-
err = os.Chdir(tempDir.Root())
90-
failNowIfError(t, err)
91-
9280
if test.setup != nil {
93-
test.setup(t)
81+
teardown := test.setup(t, test.dir)
82+
defer teardown()
9483
}
9584

9685
// remove image in case it is already present
9786
removeImage(t, test.expectImage)
98-
skaffold.Build(test.args...).RunOrFail(t)
87+
skaffold.Build(test.args...).InDir(test.dir).RunOrFail(t)
9988
checkImageExists(t, test.expectImage)
10089
})
10190
}
@@ -139,19 +128,24 @@ func checkImageExists(t *testing.T, image string) {
139128
}
140129

141130
// setupGitRepo sets up a clean repo with tag v1
142-
func setupGitRepo(t *testing.T) {
143-
multiArgs := [][]string{
131+
func setupGitRepo(t *testing.T, dir string) func() {
132+
gitArgs := [][]string{
144133
{"init"},
145134
{"add", "."},
146135
{"commit", "-m", "Initial commit"},
147136
{"tag", "v1"},
148137
}
149138

150-
for _, args := range multiArgs {
139+
for _, args := range gitArgs {
151140
cmd := exec.Command("git", args...)
141+
cmd.Dir = dir
152142
err := util.RunCmd(cmd)
153143
failNowIfError(t, err)
154144
}
145+
146+
return func() {
147+
os.RemoveAll(dir + "/.git")
148+
}
155149
}
156150

157151
// nowInChicago returns the dateTime string as generated by the dateTime tagger

0 commit comments

Comments
 (0)