mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: Improve test cleanup (#3112)
This commit is contained in:
committed by
GitHub
parent
75ff579051
commit
7d07e670ca
@ -132,6 +132,7 @@ func TestTemplateCreate(t *testing.T) {
|
||||
ProvisionDryRun: echo.ProvisionComplete,
|
||||
})
|
||||
tempDir := t.TempDir()
|
||||
removeTmpDirUntilSuccessAfterTest(t, tempDir)
|
||||
parameterFile, _ := os.CreateTemp(tempDir, "testParameterFile*.yaml")
|
||||
_, _ = parameterFile.WriteString("region: \"bananas\"")
|
||||
cmd, root := clitest.New(t, "templates", "create", "my-template", "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho), "--parameter-file", parameterFile.Name())
|
||||
@ -158,7 +159,6 @@ func TestTemplateCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
require.NoError(t, <-execDone)
|
||||
removeTmpDirUntilSuccess(t, tempDir)
|
||||
})
|
||||
|
||||
t.Run("WithParameterFileNotContainingTheValue", func(t *testing.T) {
|
||||
@ -171,6 +171,7 @@ func TestTemplateCreate(t *testing.T) {
|
||||
ProvisionDryRun: echo.ProvisionComplete,
|
||||
})
|
||||
tempDir := t.TempDir()
|
||||
removeTmpDirUntilSuccessAfterTest(t, tempDir)
|
||||
parameterFile, _ := os.CreateTemp(tempDir, "testParameterFile*.yaml")
|
||||
_, _ = parameterFile.WriteString("zone: \"bananas\"")
|
||||
cmd, root := clitest.New(t, "templates", "create", "my-template", "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho), "--parameter-file", parameterFile.Name())
|
||||
@ -196,7 +197,6 @@ func TestTemplateCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
require.EqualError(t, <-execDone, "Parameter value absent in parameter file for \"region\"!")
|
||||
removeTmpDirUntilSuccess(t, tempDir)
|
||||
})
|
||||
|
||||
t.Run("Recreate template with same name (create, delete, create)", func(t *testing.T) {
|
||||
@ -267,7 +267,7 @@ func createTestParseResponse() []*proto.Parse_Response {
|
||||
|
||||
// Need this for Windows because of a known issue with Go:
|
||||
// https://github.com/golang/go/issues/52986
|
||||
func removeTmpDirUntilSuccess(t *testing.T, tempDir string) {
|
||||
func removeTmpDirUntilSuccessAfterTest(t *testing.T, tempDir string) {
|
||||
t.Helper()
|
||||
t.Cleanup(func() {
|
||||
err := os.RemoveAll(tempDir)
|
||||
|
Reference in New Issue
Block a user