@@ -43,34 +43,40 @@ func TestBasicLine(t *testing.T) {
43
43
project := dep.Project {}
44
44
aSemverConstraint , _ := gps .NewSemverConstraint ("1.2.3" )
45
45
46
+ templateString := "PR:{{.ProjectRoot}}, Const:{{.Constraint}}, Ver:{{.Version}}, Rev:{{.Revision}}, Lat:{{.Latest}}, PkgCt:{{.PackageCount}}"
47
+ equalityTestTemplate := `{{if eq .Constraint "1.2.3"}}Constraint is 1.2.3{{end}}|{{if eq .Version "flooboo"}}Version is flooboo{{end}}|{{if eq .Latest "unknown"}}Latest is unknown{{end}}`
48
+
46
49
tests := []struct {
47
- name string
48
- status BasicStatus
49
- wantDotStatus []string
50
- wantJSONStatus []string
51
- wantTableStatus []string
52
- wantTemplateStatus []string
50
+ name string
51
+ status BasicStatus
52
+ wantDotStatus []string
53
+ wantJSONStatus []string
54
+ wantTableStatus []string
55
+ wantTemplateStatus []string
56
+ wantEqTemplateStatus []string
53
57
}{
54
58
{
55
59
name : "BasicStatus with ProjectRoot only" ,
56
60
status : BasicStatus {
57
61
ProjectRoot : "github.com/foo/bar" ,
58
62
},
59
- wantDotStatus : []string {`[label="github.com/foo/bar"];` },
60
- wantJSONStatus : []string {`"Version":""` , `"Revision":""` },
61
- wantTableStatus : []string {`github.com/foo/bar 0` },
62
- wantTemplateStatus : []string {`PR:github.com/foo/bar, Const:, Ver:, Rev:, Lat:, PkgCt:0` },
63
+ wantDotStatus : []string {`[label="github.com/foo/bar"];` },
64
+ wantJSONStatus : []string {`"Version":""` , `"Revision":""` },
65
+ wantTableStatus : []string {`github.com/foo/bar 0` },
66
+ wantTemplateStatus : []string {`PR:github.com/foo/bar, Const:, Ver:, Rev:, Lat:, PkgCt:0` },
67
+ wantEqTemplateStatus : []string {`||` },
63
68
},
64
69
{
65
70
name : "BasicStatus with Revision" ,
66
71
status : BasicStatus {
67
72
ProjectRoot : "github.com/foo/bar" ,
68
73
Revision : gps .Revision ("flooboofoobooo" ),
69
74
},
70
- wantDotStatus : []string {`[label="github.com/foo/bar\nflooboo"];` },
71
- wantJSONStatus : []string {`"Version":""` , `"Revision":"flooboofoobooo"` , `"Constraint":""` },
72
- wantTableStatus : []string {`github.com/foo/bar flooboo 0` },
73
- wantTemplateStatus : []string {`PR:github.com/foo/bar, Const:, Ver:flooboo, Rev:flooboofoobooo, Lat:, PkgCt:0` },
75
+ wantDotStatus : []string {`[label="github.com/foo/bar\nflooboo"];` },
76
+ wantJSONStatus : []string {`"Version":""` , `"Revision":"flooboofoobooo"` , `"Constraint":""` },
77
+ wantTableStatus : []string {`github.com/foo/bar flooboo 0` },
78
+ wantTemplateStatus : []string {`PR:github.com/foo/bar, Const:, Ver:flooboo, Rev:flooboofoobooo, Lat:, PkgCt:0` },
79
+ wantEqTemplateStatus : []string {`|Version is flooboo|` },
74
80
},
75
81
{
76
82
name : "BasicStatus with Version and Revision" ,
@@ -79,10 +85,11 @@ func TestBasicLine(t *testing.T) {
79
85
Version : gps .NewVersion ("1.0.0" ),
80
86
Revision : gps .Revision ("flooboofoobooo" ),
81
87
},
82
- wantDotStatus : []string {`[label="github.com/foo/bar\n1.0.0"];` },
83
- wantJSONStatus : []string {`"Version":"1.0.0"` , `"Revision":"flooboofoobooo"` , `"Constraint":""` },
84
- wantTableStatus : []string {`github.com/foo/bar 1.0.0 flooboo 0` },
85
- wantTemplateStatus : []string {`PR:github.com/foo/bar, Const:, Ver:1.0.0, Rev:flooboofoobooo, Lat:, PkgCt:0` },
88
+ wantDotStatus : []string {`[label="github.com/foo/bar\n1.0.0"];` },
89
+ wantJSONStatus : []string {`"Version":"1.0.0"` , `"Revision":"flooboofoobooo"` , `"Constraint":""` },
90
+ wantTableStatus : []string {`github.com/foo/bar 1.0.0 flooboo 0` },
91
+ wantTemplateStatus : []string {`PR:github.com/foo/bar, Const:, Ver:1.0.0, Rev:flooboofoobooo, Lat:, PkgCt:0` },
92
+ wantEqTemplateStatus : []string {`||` },
86
93
},
87
94
{
88
95
name : "BasicStatus with Constraint, Version and Revision" ,
@@ -92,21 +99,23 @@ func TestBasicLine(t *testing.T) {
92
99
Version : gps .NewVersion ("1.0.0" ),
93
100
Revision : gps .Revision ("revxyz" ),
94
101
},
95
- wantDotStatus : []string {`[label="github.com/foo/bar\n1.0.0"];` },
96
- wantJSONStatus : []string {`"Revision":"revxyz"` , `"Constraint":"1.2.3"` , `"Version":"1.0.0"` },
97
- wantTableStatus : []string {`github.com/foo/bar 1.2.3 1.0.0 revxyz 0` },
98
- wantTemplateStatus : []string {`PR:github.com/foo/bar, Const:1.2.3, Ver:1.0.0, Rev:revxyz, Lat:, PkgCt:0` },
102
+ wantDotStatus : []string {`[label="github.com/foo/bar\n1.0.0"];` },
103
+ wantJSONStatus : []string {`"Revision":"revxyz"` , `"Constraint":"1.2.3"` , `"Version":"1.0.0"` },
104
+ wantTableStatus : []string {`github.com/foo/bar 1.2.3 1.0.0 revxyz 0` },
105
+ wantTemplateStatus : []string {`PR:github.com/foo/bar, Const:1.2.3, Ver:1.0.0, Rev:revxyz, Lat:, PkgCt:0` },
106
+ wantEqTemplateStatus : []string {`Constraint is 1.2.3||` },
99
107
},
100
108
{
101
109
name : "BasicStatus with update error" ,
102
110
status : BasicStatus {
103
111
ProjectRoot : "github.com/foo/bar" ,
104
112
hasError : true ,
105
113
},
106
- wantDotStatus : []string {`[label="github.com/foo/bar"];` },
107
- wantJSONStatus : []string {`"Version":""` , `"Revision":""` , `"Latest":"unknown"` },
108
- wantTableStatus : []string {`github.com/foo/bar unknown 0` },
109
- wantTemplateStatus : []string {`PR:github.com/foo/bar, Const:, Ver:, Rev:, Lat:unknown, PkgCt:0` },
114
+ wantDotStatus : []string {`[label="github.com/foo/bar"];` },
115
+ wantJSONStatus : []string {`"Version":""` , `"Revision":""` , `"Latest":"unknown"` },
116
+ wantTableStatus : []string {`github.com/foo/bar unknown 0` },
117
+ wantTemplateStatus : []string {`PR:github.com/foo/bar, Const:, Ver:, Rev:, Lat:unknown, PkgCt:0` },
118
+ wantEqTemplateStatus : []string {`||Latest is unknown` },
110
119
},
111
120
}
112
121
@@ -159,7 +168,7 @@ func TestBasicLine(t *testing.T) {
159
168
}
160
169
161
170
buf .Reset ()
162
- template , _ := template .New ("status" ).Parse ("PR:{{.ProjectRoot}}, Const:{{.Constraint}}, Ver:{{.Version}}, Rev:{{.Revision}}, Lat:{{.Latest}}, PkgCt:{{.PackageCount}}" )
171
+ template , _ := template .New ("status" ).Parse (templateString )
163
172
templateout := & templateOutput {w : & buf , tmpl : template }
164
173
templateout .BasicHeader ()
165
174
templateout .BasicLine (& test .status )
@@ -170,6 +179,20 @@ func TestBasicLine(t *testing.T) {
170
179
t .Errorf ("Did not find expected template status: \n \t (GOT) %v \n \t (WNT) %v" , buf .String (), wantStatus )
171
180
}
172
181
}
182
+
183
+ // The following test is to ensure that certain fields usable with string operations such as .eq
184
+ buf .Reset ()
185
+ template , _ = template .New ("status" ).Parse (equalityTestTemplate )
186
+ templateout = & templateOutput {w : & buf , tmpl : template }
187
+ templateout .BasicHeader ()
188
+ templateout .BasicLine (& test .status )
189
+ templateout .BasicFooter ()
190
+
191
+ for _ , wantStatus := range test .wantEqTemplateStatus {
192
+ if ok := strings .Contains (buf .String (), wantStatus ); ! ok {
193
+ t .Errorf ("Did not find expected template status: \n \t (GOT) %v \n \t (WNT) %v" , buf .String (), wantStatus )
194
+ }
195
+ }
173
196
})
174
197
}
175
198
}
0 commit comments