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

Commite1423f5

Browse files
committed
fixup! refactor: extract WarnMatchedProvisioners to cliutil
1 parent98521be commite1423f5

File tree

2 files changed

+89
-8
lines changed

2 files changed

+89
-8
lines changed

‎cli/cliutil/provisionerwarn.go‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,30 @@ Details:
2424
`
2525
)
2626

27-
funcWarnMatchedProvisioners(w io.Writer,tv codersdk.TemplateVersion) {
28-
iftv.MatchedProvisioners==nil {
27+
// WarnMatchedProvisioners warns the user if there are no provisioners that
28+
// match the requested tags for a given provisioner job.
29+
// If the job is not pending, it is ignored.
30+
funcWarnMatchedProvisioners(w io.Writer,mp*codersdk.MatchedProvisioners,job codersdk.ProvisionerJob) {
31+
ifmp==nil {
2932
// Nothing in the response, nothing to do here!
3033
return
3134
}
35+
ifjob.Status!=codersdk.ProvisionerJobPending {
36+
// Only warn if the job is pending.
37+
return
38+
}
3239
vartagsJSON strings.Builder
33-
iferr:=json.NewEncoder(&tagsJSON).Encode(tv.Job.Tags);err!=nil {
40+
iferr:=json.NewEncoder(&tagsJSON).Encode(job.Tags);err!=nil {
3441
// Fall back to the less-pretty string representation.
3542
tagsJSON.Reset()
36-
_,_=tagsJSON.WriteString(fmt.Sprintf("%v",tv.Job.Tags))
43+
_,_=tagsJSON.WriteString(fmt.Sprintf("%v",job.Tags))
3744
}
38-
iftv.MatchedProvisioners.Count==0 {
39-
cliui.Warnf(w,warnNoMatchedProvisioners,tv.Job.ID,tagsJSON.String())
45+
ifmp.Count==0 {
46+
cliui.Warnf(w,warnNoMatchedProvisioners,job.ID,tagsJSON.String())
4047
return
4148
}
42-
iftv.MatchedProvisioners.Available==0 {
43-
cliui.Warnf(w,warnNoAvailableProvisioners,tv.Job.ID,strings.TrimSpace(tagsJSON.String()),tv.MatchedProvisioners.MostRecentlySeen.Time)
49+
ifmp.Available==0 {
50+
cliui.Warnf(w,warnNoAvailableProvisioners,job.ID,strings.TrimSpace(tagsJSON.String()),mp.MostRecentlySeen.Time)
4451
return
4552
}
4653
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package cliutil_test
2+
3+
import (
4+
"strings"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/coder/coder/v2/cli/cliutil"
10+
"github.com/coder/coder/v2/codersdk"
11+
)
12+
13+
funcTestWarnMatchedProvisioners(t*testing.T) {
14+
t.Parallel()
15+
16+
for_,tt:=range []struct {
17+
namestring
18+
mp*codersdk.MatchedProvisioners
19+
job codersdk.ProvisionerJob
20+
expectstring
21+
}{
22+
{
23+
name:"no_match",
24+
mp:&codersdk.MatchedProvisioners{
25+
Count:0,
26+
Available:0,
27+
},
28+
job: codersdk.ProvisionerJob{
29+
Status:codersdk.ProvisionerJobPending,
30+
},
31+
expect:`there are no provisioners that accept the required tags`,
32+
},
33+
{
34+
name:"no_available",
35+
mp:&codersdk.MatchedProvisioners{
36+
Count:1,
37+
Available:0,
38+
},
39+
job: codersdk.ProvisionerJob{
40+
Status:codersdk.ProvisionerJobPending,
41+
},
42+
expect:`Provisioners that accept the required tags have not responded for longer than expected`,
43+
},
44+
{
45+
name:"match",
46+
mp:&codersdk.MatchedProvisioners{
47+
Count:1,
48+
Available:1,
49+
},
50+
job: codersdk.ProvisionerJob{
51+
Status:codersdk.ProvisionerJobPending,
52+
},
53+
},
54+
{
55+
name:"not_pending",
56+
mp:&codersdk.MatchedProvisioners{},
57+
job: codersdk.ProvisionerJob{
58+
Status:codersdk.ProvisionerJobRunning,
59+
},
60+
},
61+
} {
62+
tt:=tt
63+
t.Run(tt.name,func(t*testing.T) {
64+
t.Parallel()
65+
varw strings.Builder
66+
cliutil.WarnMatchedProvisioners(&w,tt.mp,tt.job)
67+
iftt.expect!="" {
68+
require.Contains(t,w.String(),tt.expect)
69+
}else {
70+
require.Empty(t,w.String())
71+
}
72+
})
73+
}
74+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp