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

Commit ae10ff2

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

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

cmd/dep/status_test.go

+90
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,93 @@ 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+
name: "projectStatus with no upstream exists",
349+
ps: projectStatus{
350+
UpstreamExists: false,
351+
UpstreamVersionExists: false,
352+
},
353+
wantString: `
354+
PROJECT:
355+
VERSION:
356+
CONSTRAINTS: []
357+
SOURCE:
358+
ALT SOURCE:
359+
PUB VERSION:
360+
REVISION:
361+
LATEST ALLOWED:
362+
SOURCE TYPE:
363+
PACKAGES:
364+
PROJECT IMPORTERS:
365+
PACKAGE IMPORTERS:
366+
UPSTREAM EXISTS: no
367+
UPSTREAM VERSION EXISTS: no`,
368+
},
369+
}
370+
371+
for _, tc := range testCases {
372+
t.Run(tc.name, func(t *testing.T) {
373+
gotString := tc.ps.String()
374+
if gotString != tc.wantString {
375+
t.Errorf("unexpected projectStatus string: \n\t(GOT): %v\n\t(WNT): %v", gotString, tc.wantString)
376+
}
377+
})
378+
}
379+
}

0 commit comments

Comments
 (0)