forked from golang/dep
-
Notifications
You must be signed in to change notification settings - Fork 1
/
manifest_test.go
130 lines (118 loc) · 3.51 KB
/
manifest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"reflect"
"strings"
"testing"
"github.com/sdboyer/gps"
)
const je = `{
"dependencies": {
"github.com/sdboyer/gps": {
"branch": "master",
"revision": "d05d5aca9f895d19e9265839bffeadd74a2d2ecb",
"version": "^v0.12.0",
"source": "https://github.com/sdboyer/gps"
}
},
"overrides": {
"github.com/sdboyer/gps": {
"branch": "master",
"revision": "d05d5aca9f895d19e9265839bffeadd74a2d2ecb",
"version": "^v0.12.0",
"source": "https://github.com/sdboyer/gps"
}
},
"ignores": [
"github.com/foo/bar"
]
}
`
const jg = `{
"dependencies": {
"github.com/babble/brook": {
"revision": "d05d5aca9f895d19e9265839bffeadd74a2d2ecb"
},
"github.com/sdboyer/gps": {
"version": ">=0.12.0, <1.0.0"
}
},
"overrides": {
"github.com/sdboyer/gps": {
"branch": "master",
"source": "https://github.com/sdboyer/gps"
}
},
"ignores": [
"github.com/foo/bar"
]
}
`
func TestReadManifest(t *testing.T) {
_, err := readManifest(strings.NewReader(je))
if err == nil {
t.Error("Reading manifest with invalid props should have caused error, but did not")
} else if !strings.Contains(err.Error(), "multiple constraints") {
t.Errorf("Unexpected error %q; expected multiple constraint error", err)
}
m2, err := readManifest(strings.NewReader(jg))
if err != nil {
t.Fatalf("Should have read Manifest correctly, but got err %q", err)
}
c, _ := gps.NewSemverConstraint(">=0.12.0, <1.0.0")
em := manifest{
Dependencies: map[gps.ProjectRoot]gps.ProjectProperties{
gps.ProjectRoot("github.com/sdboyer/gps"): {
Constraint: c,
},
gps.ProjectRoot("github.com/babble/brook"): {
Constraint: gps.Revision("d05d5aca9f895d19e9265839bffeadd74a2d2ecb"),
},
},
Ovr: map[gps.ProjectRoot]gps.ProjectProperties{
gps.ProjectRoot("github.com/sdboyer/gps"): {
Source: "https://github.com/sdboyer/gps",
Constraint: gps.NewBranch("master"),
},
},
Ignores: []string{"github.com/foo/bar"},
}
if !reflect.DeepEqual(m2.Dependencies, em.Dependencies) {
t.Error("Valid manifest's dependencies did not parse as expected")
}
if !reflect.DeepEqual(m2.Ovr, em.Ovr) {
t.Error("Valid manifest's overrides did not parse as expected")
}
if !reflect.DeepEqual(m2.Ignores, em.Ignores) {
t.Error("Valid manifest's ignores did not parse as expected")
}
}
func TestWriteManifest(t *testing.T) {
c, _ := gps.NewSemverConstraint("^v0.12.0")
m := &manifest{
Dependencies: map[gps.ProjectRoot]gps.ProjectProperties{
gps.ProjectRoot("github.com/sdboyer/gps"): {
Constraint: c,
},
gps.ProjectRoot("github.com/babble/brook"): {
Constraint: gps.Revision("d05d5aca9f895d19e9265839bffeadd74a2d2ecb"),
},
},
Ovr: map[gps.ProjectRoot]gps.ProjectProperties{
gps.ProjectRoot("github.com/sdboyer/gps"): {
Source: "https://github.com/sdboyer/gps",
Constraint: gps.NewBranch("master"),
},
},
Ignores: []string{"github.com/foo/bar"},
}
b, err := m.MarshalJSON()
if err != nil {
t.Fatalf("Error while marshaling valid manifest to JSON: %q", err)
}
if string(b) != jg {
t.Errorf("Valid manifest did not marshal to JSON as expected:\n\t(GOT): %s\n\t(WNT): %s", string(b), jg)
}
}