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

Commit692b975

Browse files
committed
Refactor tests
1 parentd27d202 commit692b975

File tree

2 files changed

+60
-126
lines changed

2 files changed

+60
-126
lines changed

‎cli/create_test.go

Lines changed: 40 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -114,39 +114,7 @@ func TestCreate(t *testing.T) {
114114

115115
defaultValue:="something"
116116
version:=coderdtest.CreateTemplateVersion(t,client,user.OrganizationID,&echo.Responses{
117-
Parse: []*proto.Parse_Response{{
118-
Type:&proto.Parse_Response_Complete{
119-
Complete:&proto.Parse_Complete{
120-
ParameterSchemas: []*proto.ParameterSchema{
121-
{
122-
AllowOverrideSource:true,
123-
Name:"region",
124-
Description:"description 1",
125-
DefaultSource:&proto.ParameterSource{
126-
Scheme:proto.ParameterSource_DATA,
127-
Value:defaultValue,
128-
},
129-
DefaultDestination:&proto.ParameterDestination{
130-
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
131-
},
132-
},
133-
{
134-
AllowOverrideSource:true,
135-
Name:"username",
136-
Description:"description 2",
137-
DefaultSource:&proto.ParameterSource{
138-
Scheme:proto.ParameterSource_DATA,
139-
// No default value
140-
Value:"",
141-
},
142-
DefaultDestination:&proto.ParameterDestination{
143-
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
144-
},
145-
},
146-
},
147-
},
148-
},
149-
}},
117+
Parse:createTestParseResponseWithDefault(defaultValue),
150118
Provision:echo.ProvisionComplete,
151119
ProvisionDryRun:echo.ProvisionComplete,
152120
})
@@ -187,39 +155,7 @@ func TestCreate(t *testing.T) {
187155

188156
defaultValue:="something"
189157
version:=coderdtest.CreateTemplateVersion(t,client,user.OrganizationID,&echo.Responses{
190-
Parse: []*proto.Parse_Response{{
191-
Type:&proto.Parse_Response_Complete{
192-
Complete:&proto.Parse_Complete{
193-
ParameterSchemas: []*proto.ParameterSchema{
194-
{
195-
AllowOverrideSource:true,
196-
Name:"region",
197-
Description:"description 1",
198-
DefaultSource:&proto.ParameterSource{
199-
Scheme:proto.ParameterSource_DATA,
200-
Value:defaultValue,
201-
},
202-
DefaultDestination:&proto.ParameterDestination{
203-
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
204-
},
205-
},
206-
{
207-
AllowOverrideSource:true,
208-
Name:"username",
209-
Description:"description 2",
210-
DefaultSource:&proto.ParameterSource{
211-
Scheme:proto.ParameterSource_DATA,
212-
// No default value
213-
Value:"",
214-
},
215-
DefaultDestination:&proto.ParameterDestination{
216-
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
217-
},
218-
},
219-
},
220-
},
221-
},
222-
}},
158+
Parse:createTestParseResponseWithDefault(defaultValue),
223159
Provision:echo.ProvisionComplete,
224160
ProvisionDryRun:echo.ProvisionComplete,
225161
})
@@ -257,25 +193,9 @@ func TestCreate(t *testing.T) {
257193
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerD:true})
258194
user:=coderdtest.CreateFirstUser(t,client)
259195

196+
defaultValue:="something"
260197
version:=coderdtest.CreateTemplateVersion(t,client,user.OrganizationID,&echo.Responses{
261-
Parse: []*proto.Parse_Response{{
262-
Type:&proto.Parse_Response_Complete{
263-
Complete:&proto.Parse_Complete{
264-
ParameterSchemas: []*proto.ParameterSchema{{
265-
AllowOverrideSource:true,
266-
Name:"region",
267-
Description:"description",
268-
DefaultSource:&proto.ParameterSource{
269-
Scheme:proto.ParameterSource_DATA,
270-
Value:"something",
271-
},
272-
DefaultDestination:&proto.ParameterDestination{
273-
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
274-
},
275-
}},
276-
},
277-
},
278-
}},
198+
Parse:createTestParseResponseWithDefault(defaultValue),
279199
Provision:echo.ProvisionComplete,
280200
ProvisionDryRun:echo.ProvisionComplete,
281201
})
@@ -297,3 +217,39 @@ func TestCreate(t *testing.T) {
297217
<-doneChan
298218
})
299219
}
220+
221+
funccreateTestParseResponseWithDefault(defaultValuestring) []*proto.Parse_Response {
222+
return []*proto.Parse_Response{{
223+
Type:&proto.Parse_Response_Complete{
224+
Complete:&proto.Parse_Complete{
225+
ParameterSchemas: []*proto.ParameterSchema{
226+
{
227+
AllowOverrideSource:true,
228+
Name:"region",
229+
Description:"description 1",
230+
DefaultSource:&proto.ParameterSource{
231+
Scheme:proto.ParameterSource_DATA,
232+
Value:defaultValue,
233+
},
234+
DefaultDestination:&proto.ParameterDestination{
235+
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
236+
},
237+
},
238+
{
239+
AllowOverrideSource:true,
240+
Name:"username",
241+
Description:"description 2",
242+
DefaultSource:&proto.ParameterSource{
243+
Scheme:proto.ParameterSource_DATA,
244+
// No default value
245+
Value:"",
246+
},
247+
DefaultDestination:&proto.ParameterDestination{
248+
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
249+
},
250+
},
251+
},
252+
},
253+
},
254+
}}
255+
}

‎cli/templatecreate_test.go

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,7 @@ func TestTemplateCreate(t *testing.T) {
5555
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerD:true})
5656
coderdtest.CreateFirstUser(t,client)
5757
source:=clitest.CreateTemplateVersionSource(t,&echo.Responses{
58-
Parse: []*proto.Parse_Response{{
59-
Type:&proto.Parse_Response_Complete{
60-
Complete:&proto.Parse_Complete{
61-
ParameterSchemas: []*proto.ParameterSchema{{
62-
AllowOverrideSource:true,
63-
Name:"region",
64-
Description:"description",
65-
DefaultDestination:&proto.ParameterDestination{
66-
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
67-
},
68-
}},
69-
},
70-
},
71-
}},
58+
Parse:createTestParseResponse(),
7259
Provision:echo.ProvisionComplete,
7360
ProvisionDryRun:echo.ProvisionComplete,
7461
})
@@ -104,20 +91,7 @@ func TestTemplateCreate(t *testing.T) {
10491
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerD:true})
10592
coderdtest.CreateFirstUser(t,client)
10693
source:=clitest.CreateTemplateVersionSource(t,&echo.Responses{
107-
Parse: []*proto.Parse_Response{{
108-
Type:&proto.Parse_Response_Complete{
109-
Complete:&proto.Parse_Complete{
110-
ParameterSchemas: []*proto.ParameterSchema{{
111-
AllowOverrideSource:true,
112-
Name:"region",
113-
Description:"description",
114-
DefaultDestination:&proto.ParameterDestination{
115-
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
116-
},
117-
}},
118-
},
119-
},
120-
}},
94+
Parse:createTestParseResponse(),
12195
Provision:echo.ProvisionComplete,
12296
ProvisionDryRun:echo.ProvisionComplete,
12397
})
@@ -154,20 +128,7 @@ func TestTemplateCreate(t *testing.T) {
154128
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerD:true})
155129
coderdtest.CreateFirstUser(t,client)
156130
source:=clitest.CreateTemplateVersionSource(t,&echo.Responses{
157-
Parse: []*proto.Parse_Response{{
158-
Type:&proto.Parse_Response_Complete{
159-
Complete:&proto.Parse_Complete{
160-
ParameterSchemas: []*proto.ParameterSchema{{
161-
AllowOverrideSource:true,
162-
Name:"region",
163-
Description:"description",
164-
DefaultDestination:&proto.ParameterDestination{
165-
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
166-
},
167-
}},
168-
},
169-
},
170-
}},
131+
Parse:createTestParseResponse(),
171132
Provision:echo.ProvisionComplete,
172133
ProvisionDryRun:echo.ProvisionComplete,
173134
})
@@ -198,3 +159,20 @@ func TestTemplateCreate(t *testing.T) {
198159
require.EqualError(t,<-execDone,"Parameter value absent in parameter file for\"region\"!")
199160
})
200161
}
162+
163+
funccreateTestParseResponse() []*proto.Parse_Response {
164+
return []*proto.Parse_Response{{
165+
Type:&proto.Parse_Response_Complete{
166+
Complete:&proto.Parse_Complete{
167+
ParameterSchemas: []*proto.ParameterSchema{{
168+
AllowOverrideSource:true,
169+
Name:"region",
170+
Description:"description",
171+
DefaultDestination:&proto.ParameterDestination{
172+
Scheme:proto.ParameterDestination_PROVISIONER_VARIABLE,
173+
},
174+
}},
175+
},
176+
},
177+
}}
178+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp