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

Commit de981c2

Browse files
committed
test: Add TestProjectStatusString
1 parent a6ca4a8 commit de981c2

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

cmd/dep/status_test.go

+68
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,71 @@ func TestBasicStatusGetConsolidatedLatest(t *testing.T) {
287287
})
288288
}
289289
}
290+
291+
func TestProjectStatusString(t *testing.T) {
292+
testCases := []struct {
293+
name string
294+
ps projectStatus
295+
wantString string
296+
}{
297+
{
298+
name: "basic projectStatus",
299+
ps: projectStatus{
300+
Project: "github.com/x/y",
301+
Version: "v1.0",
302+
Constraints: nil,
303+
Source: "github.com/x/y",
304+
AltSource: "https://github.com/z/y",
305+
PubVersions: pubVersions{
306+
"semvers": []string{"v0.5", "v0.7", "v1.0", "v1.5"},
307+
"branches": []string{"master", "dev"},
308+
"nonsemvers": []string{"v1.0-rc1", "v1.5-rc"},
309+
},
310+
Revision: "some-rev",
311+
LatestAllowed: "some-other-rev",
312+
SourceType: "git",
313+
Packages: []string{"github.com/x/y/pkgA", "github.com/x/y/pkgB", "github.com/x/y/pkgB/foo"},
314+
ProjectImporters: projectImporters{
315+
"github.com/a/b": true,
316+
"github.com/foo/bar": true,
317+
},
318+
PackageImporters: packageImporters{
319+
"github.com/x/y/pkgA": []string{"github.com/a/b/z", "github.com/foo/bar/k"},
320+
"github.com/x/y/pkgB/foo": []string{"github.com/a/b/j"},
321+
},
322+
UpstreamExists: true,
323+
UpstreamVersionExists: true,
324+
},
325+
wantString: `
326+
PROJECT: github.com/x/y
327+
VERSION: v1.0
328+
CONSTRAINTS: []
329+
SOURCE: github.com/x/y
330+
ALT SOURCE: https://github.com/z/y
331+
PUB VERSION: branches: dev, master
332+
nonsemvers: v1.0-rc1, v1.5-rc
333+
semvers: v0.5, v0.7, v1.0, v1.5
334+
REVISION: some-rev
335+
LATEST ALLOWED: some-other-rev
336+
SOURCE TYPE: git
337+
PACKAGES: github.com/x/y/pkgA, github.com/x/y/pkgB, github.com/x/y/pkgB/foo
338+
PROJECT IMPORTERS: github.com/a/b, github.com/foo/bar
339+
PACKAGE IMPORTERS: github.com/x/y/pkgA
340+
github.com/a/b/z
341+
github.com/foo/bar/k
342+
github.com/x/y/pkgB/foo
343+
github.com/a/b/j
344+
UPSTREAM EXISTS: yes
345+
UPSTREAM VERSION EXISTS: yes`,
346+
},
347+
}
348+
349+
for _, tc := range testCases {
350+
t.Run(tc.name, func(t *testing.T) {
351+
gotString := tc.ps.String()
352+
if gotString != tc.wantString {
353+
t.Errorf("unexpected projectStatus string: \n\t(GOT): %v\n\t(WNT): %v", gotString, tc.wantString)
354+
}
355+
})
356+
}
357+
}

0 commit comments

Comments
 (0)