5
5
package main
6
6
7
7
import (
8
+ "bytes"
9
+ "encoding/json"
8
10
"reflect"
9
11
"strings"
10
12
"testing"
11
13
12
14
"github.com/sdboyer/gps"
13
15
)
14
16
15
- func TestReadManifest (t * testing.T ) {
16
- const je = `{
17
+ const je = `{
17
18
"dependencies": {
18
19
"github.com/sdboyer/gps": {
19
20
"branch": "master",
@@ -35,13 +36,13 @@ func TestReadManifest(t *testing.T) {
35
36
]
36
37
}`
37
38
38
- const jg = `{
39
+ const jg = `{
39
40
"dependencies": {
40
- "github.com/sdboyer/gps": {
41
- "version": "^v0.12.0"
42
- },
43
41
"github.com/babble/brook": {
44
42
"revision": "d05d5aca9f895d19e9265839bffeadd74a2d2ecb"
43
+ },
44
+ "github.com/sdboyer/gps": {
45
+ "version": ">=0.12.0, <1.0.0"
45
46
}
46
47
},
47
48
"overrides": {
@@ -55,6 +56,7 @@ func TestReadManifest(t *testing.T) {
55
56
]
56
57
}`
57
58
59
+ func TestReadManifest (t * testing.T ) {
58
60
_ , err := readManifest (strings .NewReader (je ))
59
61
if err == nil {
60
62
t .Error ("Reading manifest with invalid props should have caused error, but did not" )
@@ -67,7 +69,7 @@ func TestReadManifest(t *testing.T) {
67
69
t .Fatalf ("Should have read Manifest correctly, but got err %q" , err )
68
70
}
69
71
70
- c , _ := gps .NewSemverConstraint ("^v0 .12.0" )
72
+ c , _ := gps .NewSemverConstraint (">=0 .12.0, <1.0 .0" )
71
73
em := manifest {
72
74
Dependencies : map [gps.ProjectRoot ]gps.ProjectProperties {
73
75
gps .ProjectRoot ("github.com/sdboyer/gps" ): {
@@ -96,3 +98,42 @@ func TestReadManifest(t *testing.T) {
96
98
t .Error ("Valid manifest's ignores did not parse as expected" )
97
99
}
98
100
}
101
+
102
+ func TestWriteManifest (t * testing.T ) {
103
+ c , _ := gps .NewSemverConstraint ("^v0.12.0" )
104
+ m := & manifest {
105
+ Dependencies : map [gps.ProjectRoot ]gps.ProjectProperties {
106
+ gps .ProjectRoot ("github.com/sdboyer/gps" ): {
107
+ Constraint : c ,
108
+ },
109
+ gps .ProjectRoot ("github.com/babble/brook" ): {
110
+ Constraint : gps .Revision ("d05d5aca9f895d19e9265839bffeadd74a2d2ecb" ),
111
+ },
112
+ },
113
+ Ovr : map [gps.ProjectRoot ]gps.ProjectProperties {
114
+ gps .ProjectRoot ("github.com/sdboyer/gps" ): {
115
+ NetworkName : "https://github.com/sdboyer/gps" ,
116
+ Constraint : gps .NewBranch ("master" ),
117
+ },
118
+ },
119
+ Ignores : []string {"github.com/foo/bar" },
120
+ }
121
+
122
+ b , err := json .Marshal (m )
123
+ if err != nil {
124
+ t .Fatalf ("Error while marshaling valid manifest to JSON: %q" , err )
125
+ }
126
+
127
+ var out bytes.Buffer
128
+ json .Indent (& out , b , "" , " " )
129
+ b = out .Bytes ()
130
+ // uuuuuughhhhh
131
+ b = bytes .Replace (b , []byte ("\\ u003c" ), []byte ("<" ), - 1 )
132
+ b = bytes .Replace (b , []byte ("\\ u003e" ), []byte (">" ), - 1 )
133
+
134
+ //s := out.String()
135
+ s := string (b )
136
+ if s != jg {
137
+ t .Errorf ("Valid manifest did not marshal to JSON as expected:\n \t (GOT): %s\n \t (WNT): %s" , s , jg )
138
+ }
139
+ }
0 commit comments