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

Commit 532c0f2

Browse files
committed
dep: add NewManifest
This commit adds a constructor for dep.Manifest. Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 53e80dc commit 532c0f2

12 files changed

+58
-75
lines changed

cmd/dep/ensure.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,8 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
603603

604604
// Prep post-actions and feedback from adds.
605605
var reqlist []string
606-
appender := &dep.Manifest{
607-
Constraints: make(gps.ProjectConstraints),
608-
}
606+
appender := dep.NewManifest()
607+
609608
for pr, instr := range addInstructions {
610609
for path := range instr.ephReq {
611610
reqlist = append(reqlist, path)

cmd/dep/glide_importer.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ func (g *glideImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e
141141
task.WriteString("...")
142142
g.logger.Println(task)
143143

144-
manifest := &dep.Manifest{
145-
Constraints: make(gps.ProjectConstraints),
146-
}
144+
manifest := dep.NewManifest()
147145

148146
for _, pkg := range append(g.yaml.Imports, g.yaml.TestImports...) {
149147
pc, err := g.buildProjectConstraint(pkg)

cmd/dep/godep_importer.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ func (g *godepImporter) load(projectDir string) error {
8888
func (g *godepImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) {
8989
g.logger.Println("Converting from Godeps.json ...")
9090

91-
manifest := &dep.Manifest{
92-
Constraints: make(gps.ProjectConstraints),
93-
}
91+
manifest := dep.NewManifest()
9492
lock := &dep.Lock{}
9593

9694
for _, pkg := range g.json.Imports {

cmd/dep/godep_importer_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func TestGodepConfig_Convert(t *testing.T) {
5252
},
5353
},
5454
convertTestCase: &convertTestCase{
55-
5655
projectRoot: gps.ProjectRoot("github.com/sdboyer/deptest"),
5756
wantConstraint: "^1.12.0-12-g2fd980e",
5857
wantLockCount: 1,
@@ -70,7 +69,6 @@ func TestGodepConfig_Convert(t *testing.T) {
7069
},
7170
},
7271
convertTestCase: &convertTestCase{
73-
7472
projectRoot: gps.ProjectRoot("github.com/sdboyer/deptest"),
7573
wantConstraint: "^1.0.0",
7674
wantRevision: gps.Revision("ff2948a2ac8f538c4ecd55962e919d1e13e74baf"),
@@ -83,7 +81,6 @@ func TestGodepConfig_Convert(t *testing.T) {
8381
Imports: []godepPackage{{ImportPath: ""}},
8482
},
8583
convertTestCase: &convertTestCase{
86-
8784
wantConvertErr: true,
8885
},
8986
},
@@ -96,7 +93,6 @@ func TestGodepConfig_Convert(t *testing.T) {
9693
},
9794
},
9895
convertTestCase: &convertTestCase{
99-
10096
wantConvertErr: true,
10197
},
10298
},
@@ -116,7 +112,6 @@ func TestGodepConfig_Convert(t *testing.T) {
116112
},
117113
},
118114
convertTestCase: &convertTestCase{
119-
120115
projectRoot: gps.ProjectRoot("github.com/sdboyer/deptest"),
121116
wantLockCount: 1,
122117
wantConstraint: "^1.0.0",

cmd/dep/gopath_scanner.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ func (g *gopathScanner) InitializeRootManifestAndLock(rootM *dep.Manifest, rootL
5252
return err
5353
}
5454

55-
g.origM = &dep.Manifest{
56-
Constraints: g.pd.constraints,
57-
Ovr: make(gps.ProjectConstraints),
58-
}
55+
g.origM = dep.NewManifest()
56+
g.origM.Constraints = g.pd.constraints
57+
5958
g.origL = &dep.Lock{
6059
P: make([]gps.LockedProject, 0, len(g.pd.ondisk)),
6160
}

cmd/dep/gopath_scanner_test.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,14 @@ func TestGopathScanner_OverlayManifestConstraints(t *testing.T) {
2727
v1 := gps.NewVersion("v1.0.0")
2828
v2 := gps.NewVersion("v2.0.0")
2929
v3 := gps.NewVersion("v3.0.0")
30-
rootM := &dep.Manifest{
31-
Constraints: gps.ProjectConstraints{
32-
pi1.ProjectRoot: gps.ProjectProperties{Constraint: v1},
33-
},
34-
}
30+
rootM := dep.NewManifest()
31+
rootM.Constraints[pi1.ProjectRoot] = gps.ProjectProperties{Constraint: v1}
3532
rootL := &dep.Lock{}
33+
origM := dep.NewManifest()
34+
origM.Constraints[pi1.ProjectRoot] = gps.ProjectProperties{Constraint: v2}
35+
origM.Constraints[pi2.ProjectRoot] = gps.ProjectProperties{Constraint: v3}
3636
gs := gopathScanner{
37-
origM: &dep.Manifest{
38-
Constraints: gps.ProjectConstraints{
39-
pi1.ProjectRoot: gps.ProjectProperties{Constraint: v2},
40-
pi2.ProjectRoot: gps.ProjectProperties{Constraint: v3},
41-
},
42-
},
37+
origM: origM,
4338
origL: &dep.Lock{},
4439
ctx: ctx,
4540
pd: projectData{
@@ -79,7 +74,7 @@ func TestGopathScanner_OverlayLockProjects(t *testing.T) {
7974
h := test.NewHelper(t)
8075
ctx := newTestContext(h)
8176

82-
rootM := &dep.Manifest{}
77+
rootM := dep.NewManifest()
8378
pi1 := gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(testProject1)}
8479
pi2 := gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(testProject2)}
8580
v1 := gps.NewVersion("v1.0.0")
@@ -89,7 +84,7 @@ func TestGopathScanner_OverlayLockProjects(t *testing.T) {
8984
P: []gps.LockedProject{gps.NewLockedProject(pi1, v1, []string{})},
9085
}
9186
gs := gopathScanner{
92-
origM: &dep.Manifest{Constraints: make(gps.ProjectConstraints)},
87+
origM: dep.NewManifest(),
9388
origL: &dep.Lock{
9489
P: []gps.LockedProject{
9590
gps.NewLockedProject(pi1, v2, []string{}), // ignored, already exists in lock

cmd/dep/root_analyzer.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ func (a *rootAnalyzer) InitializeRootManifestAndLock(dir string, pr gps.ProjectR
5252
}
5353

5454
if rootM == nil {
55-
rootM = &dep.Manifest{
56-
Constraints: make(gps.ProjectConstraints),
57-
Ovr: make(gps.ProjectConstraints),
58-
}
55+
rootM = dep.NewManifest()
5956
}
6057
if rootL == nil {
6158
rootL = &dep.Lock{}
@@ -88,7 +85,8 @@ func (a *rootAnalyzer) importManifestAndLock(dir string, pr gps.ProjectRoot, sup
8885
}
8986
}
9087

91-
var emptyManifest = &dep.Manifest{Constraints: make(gps.ProjectConstraints), Ovr: make(gps.ProjectConstraints)}
88+
var emptyManifest = dep.NewManifest()
89+
9290
return emptyManifest, nil, nil
9391
}
9492

cmd/dep/vndr_importer.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,9 @@ func (v *vndrImporter) loadVndrFile(dir string) error {
8686

8787
func (v *vndrImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) {
8888
var (
89-
manifest = &dep.Manifest{
90-
Constraints: make(gps.ProjectConstraints),
91-
}
92-
lock = &dep.Lock{}
93-
err error
89+
manifest = dep.NewManifest()
90+
lock = &dep.Lock{}
91+
err error
9492
)
9593

9694
for _, pkg := range v.packages {

cmd/dep/vndr_importer_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,13 @@ func TestVndrConfig_Import(t *testing.T) {
175175

176176
constraint, err := gps.NewSemverConstraint("^2.0.0")
177177
h.Must(err)
178-
wantM := &dep.Manifest{
179-
Constraints: gps.ProjectConstraints{
180-
"github.com/sdboyer/deptest": gps.ProjectProperties{
181-
Source: "https://github.com/sdboyer/deptest.git",
182-
Constraint: gps.Revision("3f4c3bea144e112a69bbe5d8d01c1b09a544253f"),
183-
},
184-
"github.com/sdboyer/deptestdos": gps.ProjectProperties{
185-
Constraint: constraint,
186-
},
187-
},
178+
wantM := dep.NewManifest()
179+
wantM.Constraints["github.com/sdboyer/deptest"] = gps.ProjectProperties{
180+
Source: "https://github.com/sdboyer/deptest.git",
181+
Constraint: gps.Revision("3f4c3bea144e112a69bbe5d8d01c1b09a544253f"),
182+
}
183+
wantM.Constraints["github.com/sdboyer/deptestdos"] = gps.ProjectProperties{
184+
Constraint: constraint,
188185
}
189186
if !reflect.DeepEqual(wantM, m) {
190187
t.Errorf("unexpected manifest\nhave=%+v\nwant=%+v", m, wantM)

manifest.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ type rawProject struct {
5151
Source string `toml:"source,omitempty"`
5252
}
5353

54+
// NewManifest instantites a new manifest.
55+
func NewManifest() *Manifest {
56+
return &Manifest{
57+
Constraints: make(gps.ProjectConstraints),
58+
Ovr: make(gps.ProjectConstraints),
59+
}
60+
}
61+
5462
func validateManifest(s string) ([]error, error) {
5563
var warns []error
5664
// Load the TomlTree from string
@@ -141,7 +149,7 @@ func validateManifest(s string) ([]error, error) {
141149
}
142150
}
143151
default:
144-
warns = append(warns, fmt.Errorf("Unknown field in manifest: %v", prop))
152+
warns = append(warns, fmt.Errorf("unknown field in manifest: %v", prop))
145153
}
146154
}
147155

@@ -172,12 +180,12 @@ func readManifest(r io.Reader) (*Manifest, []error, error) {
172180
}
173181

174182
func fromRawManifest(raw rawManifest) (*Manifest, error) {
175-
m := &Manifest{
176-
Constraints: make(gps.ProjectConstraints, len(raw.Constraints)),
177-
Ovr: make(gps.ProjectConstraints, len(raw.Overrides)),
178-
Ignored: raw.Ignored,
179-
Required: raw.Required,
180-
}
183+
m := NewManifest()
184+
185+
m.Constraints = make(gps.ProjectConstraints, len(raw.Constraints))
186+
m.Ovr = make(gps.ProjectConstraints, len(raw.Overrides))
187+
m.Ignored = raw.Ignored
188+
m.Required = raw.Required
181189

182190
for i := 0; i < len(raw.Constraints); i++ {
183191
name, prj, err := toProject(raw.Constraints[i])

manifest_test.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,18 @@ func TestWriteManifest(t *testing.T) {
6262
golden := "manifest/golden.toml"
6363
want := h.GetTestFileString(golden)
6464
c, _ := gps.NewSemverConstraint("^0.12.0")
65-
m := &Manifest{
66-
Constraints: map[gps.ProjectRoot]gps.ProjectProperties{
67-
gps.ProjectRoot("github.com/golang/dep/internal/gps"): {
68-
Constraint: c,
69-
},
70-
gps.ProjectRoot("github.com/babble/brook"): {
71-
Constraint: gps.Revision("d05d5aca9f895d19e9265839bffeadd74a2d2ecb"),
72-
},
73-
},
74-
Ovr: map[gps.ProjectRoot]gps.ProjectProperties{
75-
gps.ProjectRoot("github.com/golang/dep/internal/gps"): {
76-
Source: "https://github.com/golang/dep/internal/gps",
77-
Constraint: gps.NewBranch("master"),
78-
},
79-
},
80-
Ignored: []string{"github.com/foo/bar"},
65+
m := NewManifest()
66+
m.Constraints[gps.ProjectRoot("github.com/golang/dep/internal/gps")] = gps.ProjectProperties{
67+
Constraint: c,
68+
}
69+
m.Constraints[gps.ProjectRoot("github.com/babble/brook")] = gps.ProjectProperties{
70+
Constraint: gps.Revision("d05d5aca9f895d19e9265839bffeadd74a2d2ecb"),
71+
}
72+
m.Ovr[gps.ProjectRoot("github.com/golang/dep/internal/gps")] = gps.ProjectProperties{
73+
Source: "https://github.com/golang/dep/internal/gps",
74+
Constraint: gps.NewBranch("master"),
8175
}
76+
m.Ignored = []string{"github.com/foo/bar"}
8277

8378
got, err := m.MarshalTOML()
8479
if err != nil {

project_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ func TestFindRoot(t *testing.T) {
6262
}
6363

6464
func TestProjectMakeParams(t *testing.T) {
65+
m := NewManifest()
66+
m.Ignored = []string{"ignoring this"}
67+
6568
p := Project{
6669
AbsRoot: "someroot",
6770
ImportRoot: gps.ProjectRoot("Some project root"),
68-
Manifest: &Manifest{Ignored: []string{"ignoring this"}},
71+
Manifest: m,
6972
Lock: &Lock{},
7073
}
7174

0 commit comments

Comments
 (0)