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

Commit 0cf51a3

Browse files
committed
feat(gb): add more tests for the gb importer
1 parent c1167c6 commit 0cf51a3

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

cmd/dep/gb_importer_test.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ import (
1717

1818
const testGbProjectRoot = "github.com/golang/notexist"
1919

20+
func TestGbConfig_ImportNoVendor(t *testing.T) {
21+
h := test.NewHelper(t)
22+
defer h.Cleanup()
23+
24+
ctx := newTestContext(h)
25+
sm, err := ctx.SourceManager()
26+
h.Must(err)
27+
defer sm.Release()
28+
29+
h.TempDir(filepath.Join("src", testGbProjectRoot, "vendor"))
30+
h.TempCopy(filepath.Join(testGbProjectRoot, "vendor", "_not-a-manifest"), "gb/manifest")
31+
projectRoot := h.Path(testGbProjectRoot)
32+
33+
// Capture stderr so we can verify output
34+
verboseOutput := &bytes.Buffer{}
35+
ctx.Err = log.New(verboseOutput, "", 0)
36+
37+
g := newGbImporter(ctx.Err, false, sm) // Disable verbose so that we don't print values that change each test run
38+
if g.HasDepMetadata(projectRoot) {
39+
t.Fatal("Expected the importer to return false if there's no vendor manifest")
40+
}
41+
}
42+
2043
func TestGbConfig_Import(t *testing.T) {
2144
h := test.NewHelper(t)
2245
defer h.Cleanup()
@@ -35,6 +58,9 @@ func TestGbConfig_Import(t *testing.T) {
3558
ctx.Err = log.New(verboseOutput, "", 0)
3659

3760
g := newGbImporter(ctx.Err, false, sm) // Disable verbose so that we don't print values that change each test run
61+
if g.Name() != "gb" {
62+
t.Fatal("Expected the importer to return the name 'gb'")
63+
}
3864
if !g.HasDepMetadata(projectRoot) {
3965
t.Fatal("Expected the importer to detect the gb manifest file")
4066
}
@@ -144,7 +170,7 @@ func TestGbConfig_Convert_Project(t *testing.T) {
144170
}
145171
}
146172

147-
func TestGbConfig_Convert_BadInput_EmptyPackageName(t *testing.T) {
173+
func TestGbConfig_Convert_BadInput(t *testing.T) {
148174
h := test.NewHelper(t)
149175
defer h.Cleanup()
150176

@@ -162,4 +188,14 @@ func TestGbConfig_Convert_BadInput_EmptyPackageName(t *testing.T) {
162188
if err == nil {
163189
t.Fatal("Expected conversion to fail because the package name is empty")
164190
}
191+
192+
g = newGbImporter(ctx.Err, true, sm)
193+
g.manifest = gbManifest{
194+
Dependencies: []gbDependency{{Importpath: "github.com/sdboyer/deptest"}},
195+
}
196+
197+
_, _, err = g.convert(testGbProjectRoot)
198+
if err == nil {
199+
t.Fatal("Expected conversion to fail because the package has no revision")
200+
}
165201
}

0 commit comments

Comments
 (0)