test(cli): Fix TestTemplatePush/UseWorkingDir bad use of chdir (#7160)

This commit is contained in:
Mathias Fredriksson
2023-04-17 17:58:25 +03:00
committed by GitHub
parent 53f521aaf9
commit 51841e9e11
2 changed files with 29 additions and 12 deletions

View File

@ -159,6 +159,8 @@ func TestTemplatePush(t *testing.T) {
// This test modifies the working directory.
//nolint:paralleltest
t.Run("UseWorkingDir", func(t *testing.T) {
t.Parallel()
if runtime.GOOS == "windows" {
t.Skip(`On Windows this test flakes with: "The process cannot access the file because it is being used by another process"`)
}
@ -179,15 +181,9 @@ func TestTemplatePush(t *testing.T) {
r.Name = filepath.Base(source)
})
oldDir, err := os.Getwd()
require.NoError(t, err)
os.Chdir(source)
defer os.Chdir(oldDir)
// Don't pass the name of the template, it should use the
// directory of the source.
inv, root := clitest.New(t, "templates", "push", "--test.provisioner", string(database.ProvisionerTypeEcho))
inv, root := clitest.New(t, "templates", "push", "--test.provisioner", string(database.ProvisionerTypeEcho), "--test.workdir", source)
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t).Attach(inv)