Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit c4b6589

Browse files
committed
Squash the binary.
1 parent a0930b9 commit c4b6589

File tree

2 files changed

+56
-34
lines changed

2 files changed

+56
-34
lines changed

cmd/dep/status.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/pkg/errors"
2525
)
2626

27+
const availableTemplateVariables = "ProjectRoot, Constraint, Version, Revision, Latest, and PackageCount."
28+
2729
const statusShortHelp = `Report the status of the project's dependencies`
2830
const statusLongHelp = `
2931
With no arguments, print the status of each dependency of the project.
@@ -43,7 +45,7 @@ print an extended status output for each dependency of the project.
4345
4446
You may use the -f flag to create a custom format for the output of the
4547
dep status command. The available fields you can utilize are as follows:
46-
ProjectRoot, Constraint, Version, Revision, Latest, and PackageCount.
48+
` + availableTemplateVariables + `
4749
4850
Status returns exit code zero if all dependencies are in a "good state".
4951
`
@@ -59,8 +61,8 @@ dep status -f='{{if eq .Constraint "master"}}{{.ProjectRoot}} {{end}}'
5961
6062
Display the list of package names constrained on the master branch.
6163
The -f flag allows you to use Go templates along with it's various
62-
constructs for formating the output data. See -help for available
63-
variables for this flag.
64+
constructs for formating the output data. Available flags are as follows:
65+
` + availableTemplateVariables + `
6466
6567
dep status -json
6668
@@ -243,10 +245,7 @@ func (out *templateOutput) BasicHeader() error { return nil }
243245
func (out *templateOutput) BasicFooter() error { return nil }
244246

245247
func (out *templateOutput) BasicLine(bs *BasicStatus) error {
246-
data := struct {
247-
ProjectRoot, Constraint, Version, Revision, Latest string
248-
PackageCount int
249-
}{
248+
data := rawStatus{
250249
ProjectRoot: bs.ProjectRoot,
251250
Constraint: bs.getConsolidatedConstraint(),
252251
Version: bs.getConsolidatedVersion(),

cmd/dep/status_test.go

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,40 @@ func TestBasicLine(t *testing.T) {
4343
project := dep.Project{}
4444
aSemverConstraint, _ := gps.NewSemverConstraint("1.2.3")
4545

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+
4649
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
5357
}{
5458
{
5559
name: "BasicStatus with ProjectRoot only",
5660
status: BasicStatus{
5761
ProjectRoot: "github.com/foo/bar",
5862
},
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{`||`},
6368
},
6469
{
6570
name: "BasicStatus with Revision",
6671
status: BasicStatus{
6772
ProjectRoot: "github.com/foo/bar",
6873
Revision: gps.Revision("flooboofoobooo"),
6974
},
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|`},
7480
},
7581
{
7682
name: "BasicStatus with Version and Revision",
@@ -79,10 +85,11 @@ func TestBasicLine(t *testing.T) {
7985
Version: gps.NewVersion("1.0.0"),
8086
Revision: gps.Revision("flooboofoobooo"),
8187
},
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{`||`},
8693
},
8794
{
8895
name: "BasicStatus with Constraint, Version and Revision",
@@ -92,21 +99,23 @@ func TestBasicLine(t *testing.T) {
9299
Version: gps.NewVersion("1.0.0"),
93100
Revision: gps.Revision("revxyz"),
94101
},
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||`},
99107
},
100108
{
101109
name: "BasicStatus with update error",
102110
status: BasicStatus{
103111
ProjectRoot: "github.com/foo/bar",
104112
hasError: true,
105113
},
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`},
110119
},
111120
}
112121

@@ -159,7 +168,7 @@ func TestBasicLine(t *testing.T) {
159168
}
160169

161170
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)
163172
templateout := &templateOutput{w: &buf, tmpl: template}
164173
templateout.BasicHeader()
165174
templateout.BasicLine(&test.status)
@@ -170,6 +179,20 @@ func TestBasicLine(t *testing.T) {
170179
t.Errorf("Did not find expected template status: \n\t(GOT) %v \n\t(WNT) %v", buf.String(), wantStatus)
171180
}
172181
}
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+
}
173196
})
174197
}
175198
}

0 commit comments

Comments
 (0)