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

Commit 1dc2d8b

Browse files
sigmacarolynvs
authored andcommitted
godep: Import additional packages as required (#1640)
* godep: Import additional packages as required In a godep manifest, entries in Packages are commonly used to specify extra dependencies of a project, like tools (code generators for example). Adding those same packages to dep's "required" entry achieves the same. * importertest: Add ability to validate required entries This mirrors what is done for ignored, as both fields are similar. * godep: Add tests to validate godep conversion of Packages. We expect to map non-local Packages in godep manifest to required entries in dep.
1 parent f66513f commit 1dc2d8b

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

internal/importers/godep/importer.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"log"
1111
"os"
1212
"path/filepath"
13+
"strings"
1314

1415
"github.com/golang/dep"
1516
"github.com/golang/dep/gps"
@@ -31,7 +32,8 @@ func NewImporter(logger *log.Logger, verbose bool, sm gps.SourceManager) *Import
3132
}
3233

3334
type godepJSON struct {
34-
Imports []godepPackage `json:"Deps"`
35+
Required []string `json:"Packages"`
36+
Imports []godepPackage `json:"Deps"`
3537
}
3638

3739
type godepPackage struct {
@@ -113,5 +115,14 @@ func (g *Importer) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock) {
113115
}
114116

115117
g.ImportPackages(packages, true)
118+
required := make([]string, 0, len(g.json.Required))
119+
for _, req := range g.json.Required {
120+
if !strings.HasPrefix(req, ".") { // ignore project packages
121+
required = append(required, req)
122+
}
123+
}
124+
if len(required) > 0 {
125+
g.Manifest.Required = required
126+
}
116127
return g.Manifest, g.Lock
117128
}

internal/importers/godep/importer_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ func TestGodepConfig_Convert(t *testing.T) {
7777
},
7878
},
7979
},
80+
"package with requirements": {
81+
importertest.TestCase{
82+
WantRequired: []string{importertest.Project},
83+
},
84+
godepJSON{
85+
Required: []string{importertest.Project},
86+
},
87+
},
88+
"package with local requirements": {
89+
importertest.TestCase{
90+
WantRequired: nil,
91+
},
92+
godepJSON{
93+
Required: []string{"./..."},
94+
},
95+
},
8096
}
8197

8298
for name, testCase := range testCases {

internal/importers/importertest/testcase.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type TestCase struct {
2727
WantRevision gps.Revision
2828
WantVersion string
2929
WantIgnored []string
30+
WantRequired []string
3031
WantWarning string
3132
}
3233

@@ -71,6 +72,11 @@ func (tc TestCase) validate(manifest *dep.Manifest, lock *dep.Lock, output *byte
7172
manifest.Ignored, tc.WantIgnored)
7273
}
7374

75+
if !equalSlice(manifest.Required, tc.WantRequired) {
76+
return errors.Errorf("unexpected set of required projects: \n\t(GOT) %#v \n\t(WNT) %#v",
77+
manifest.Required, tc.WantRequired)
78+
}
79+
7480
wantConstraintCount := 0
7581
if tc.WantConstraint != "" {
7682
wantConstraintCount = 1

0 commit comments

Comments
 (0)