Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1491620

Browse files
committed
Fix unit tests for Windows
1 parent1a12be1 commit1491620

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

‎cli/create_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ func TestCreate(t *testing.T) {
162162

163163
coderdtest.AwaitTemplateVersionJob(t,client,version.ID)
164164
_=coderdtest.CreateTemplate(t,client,user.OrganizationID,version.ID)
165-
parameterFile,_:=os.CreateTemp(t.TempDir(),"testParameterFile*.yaml")
165+
tempDir:=t.TempDir()
166+
parameterFile,_:=os.CreateTemp(tempDir,"testParameterFile*.yaml")
166167
_,_=parameterFile.WriteString("region:\"bingo\"\nusername:\"boingo\"")
167168
cmd,root:=clitest.New(t,"create","","--parameter-file",parameterFile.Name())
168169
clitest.SetupConfig(t,client,root)
@@ -187,6 +188,7 @@ func TestCreate(t *testing.T) {
187188
pty.WriteLine(value)
188189
}
189190
<-doneChan
191+
removeTmpDirUntilSuccess(t,tempDir)
190192
})
191193
t.Run("WithParameterFileNotContainingTheValue",func(t*testing.T) {
192194
t.Parallel()
@@ -201,7 +203,8 @@ func TestCreate(t *testing.T) {
201203
})
202204
coderdtest.AwaitTemplateVersionJob(t,client,version.ID)
203205
template:=coderdtest.CreateTemplate(t,client,user.OrganizationID,version.ID)
204-
parameterFile,_:=os.CreateTemp(t.TempDir(),"testParameterFile*.yaml")
206+
tempDir:=t.TempDir()
207+
parameterFile,_:=os.CreateTemp(tempDir,"testParameterFile*.yaml")
205208
_,_=parameterFile.WriteString("zone:\"bananas\"")
206209
cmd,root:=clitest.New(t,"create","my-workspace","--template",template.Name,"--parameter-file",parameterFile.Name())
207210
clitest.SetupConfig(t,client,root)
@@ -215,6 +218,7 @@ func TestCreate(t *testing.T) {
215218
require.EqualError(t,err,"Parameter value absent in parameter file for\"region\"!")
216219
}()
217220
<-doneChan
221+
removeTmpDirUntilSuccess(t,tempDir)
218222
})
219223
}
220224

‎cli/parameter_internal_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ func TestCreateParameterMapFromFile(t *testing.T) {
1212
t.Parallel()
1313
t.Run("CreateParameterMapFromFile",func(t*testing.T) {
1414
t.Parallel()
15-
parameterFile,_:=os.CreateTemp(t.TempDir(),"testParameterFile*.yaml")
15+
tempDir:=t.TempDir()
16+
parameterFile,_:=os.CreateTemp(tempDir,"testParameterFile*.yaml")
1617
_,_=parameterFile.WriteString("region:\"bananas\"\ndisk:\"20\"\n")
1718

1819
parameterMapFromFile,err:=createParameterMapFromFile(parameterFile.Name())
@@ -25,7 +26,7 @@ func TestCreateParameterMapFromFile(t *testing.T) {
2526
assert.Equal(t,expectedMap,parameterMapFromFile)
2627
assert.Nil(t,err)
2728

28-
removeTmpDirUntilSuccess(t)
29+
removeTmpDirUntilSuccess(t,tempDir)
2930
})
3031
t.Run("WithEmptyFilename",func(t*testing.T) {
3132
t.Parallel()
@@ -52,23 +53,25 @@ func TestCreateParameterMapFromFile(t *testing.T) {
5253
})
5354
t.Run("WithInvalidYAML",func(t*testing.T) {
5455
t.Parallel()
55-
parameterFile,_:=os.CreateTemp(t.TempDir(),"testParameterFile*.yaml")
56+
tempDir:=t.TempDir()
57+
parameterFile,_:=os.CreateTemp(tempDir,"testParameterFile*.yaml")
5658
_,_=parameterFile.WriteString("region =\"bananas\"\ndisk =\"20\"\n")
5759

5860
parameterMapFromFile,err:=createParameterMapFromFile(parameterFile.Name())
5961

6062
assert.Nil(t,parameterMapFromFile)
6163
assert.EqualError(t,err,"yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `region ...` into map[string]string")
6264

63-
removeTmpDirUntilSuccess(t)
65+
removeTmpDirUntilSuccess(t,tempDir)
6466
})
6567
}
6668

67-
funcremoveTmpDirUntilSuccess(t*testing.T) {
69+
funcremoveTmpDirUntilSuccess(t*testing.T,tempDirstring) {
70+
t.Helper()
6871
t.Cleanup(func() {
69-
err:=os.RemoveAll(t.TempDir())
72+
err:=os.RemoveAll(tempDir)
7073
forerr!=nil {
71-
err=os.RemoveAll(t.TempDir())
74+
err=os.RemoveAll(tempDir)
7275
}
7376
})
7477
}

‎cli/templatecreate_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ func TestTemplateCreate(t *testing.T) {
9595
Provision:echo.ProvisionComplete,
9696
ProvisionDryRun:echo.ProvisionComplete,
9797
})
98-
parameterFile,_:=os.CreateTemp(t.TempDir(),"testParameterFile*.yaml")
98+
tempDir:=t.TempDir()
99+
parameterFile,_:=os.CreateTemp(tempDir,"testParameterFile*.yaml")
99100
_,_=parameterFile.WriteString("region:\"bananas\"")
100101
cmd,root:=clitest.New(t,"templates","create","my-template","--directory",source,"--test.provisioner",string(database.ProvisionerTypeEcho),"--parameter-file",parameterFile.Name())
101102
clitest.SetupConfig(t,client,root)
@@ -121,6 +122,7 @@ func TestTemplateCreate(t *testing.T) {
121122
}
122123

123124
require.NoError(t,<-execDone)
125+
removeTmpDirUntilSuccess(t,tempDir)
124126
})
125127

126128
t.Run("WithParameterFileNotContainingTheValue",func(t*testing.T) {
@@ -132,7 +134,8 @@ func TestTemplateCreate(t *testing.T) {
132134
Provision:echo.ProvisionComplete,
133135
ProvisionDryRun:echo.ProvisionComplete,
134136
})
135-
parameterFile,_:=os.CreateTemp(t.TempDir(),"testParameterFile*.yaml")
137+
tempDir:=t.TempDir()
138+
parameterFile,_:=os.CreateTemp(tempDir,"testParameterFile*.yaml")
136139
_,_=parameterFile.WriteString("zone:\"bananas\"")
137140
cmd,root:=clitest.New(t,"templates","create","my-template","--directory",source,"--test.provisioner",string(database.ProvisionerTypeEcho),"--parameter-file",parameterFile.Name())
138141
clitest.SetupConfig(t,client,root)
@@ -157,6 +160,7 @@ func TestTemplateCreate(t *testing.T) {
157160
}
158161

159162
require.EqualError(t,<-execDone,"Parameter value absent in parameter file for\"region\"!")
163+
removeTmpDirUntilSuccess(t,tempDir)
160164
})
161165
}
162166

@@ -176,3 +180,13 @@ func createTestParseResponse() []*proto.Parse_Response {
176180
},
177181
}}
178182
}
183+
184+
funcremoveTmpDirUntilSuccess(t*testing.T,tempDirstring) {
185+
t.Helper()
186+
t.Cleanup(func() {
187+
err:=os.RemoveAll(tempDir)
188+
forerr!=nil {
189+
err=os.RemoveAll(tempDir)
190+
}
191+
})
192+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp