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

Commit 9d759ef

Browse files
committed
Add tests for writing manifest
1 parent 0c1f9d2 commit 9d759ef

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

manifest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func toPossible(pp gps.ProjectProperties) (p possibleProps) {
135135

136136
if v, ok := pp.Constraint.(gps.Version); ok {
137137
switch v.Type() {
138-
case "revision":
138+
case "rev": // will be changed to revision upstream soon
139139
p.Revision = v.String()
140140
case "branch":
141141
p.Branch = v.String()

manifest_test.go

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
package main
66

77
import (
8+
"bytes"
9+
"encoding/json"
810
"reflect"
911
"strings"
1012
"testing"
1113

1214
"github.com/sdboyer/gps"
1315
)
1416

15-
func TestReadManifest(t *testing.T) {
16-
const je = `{
17+
const je = `{
1718
"dependencies": {
1819
"github.com/sdboyer/gps": {
1920
"branch": "master",
@@ -35,13 +36,13 @@ func TestReadManifest(t *testing.T) {
3536
]
3637
}`
3738

38-
const jg = `{
39+
const jg = `{
3940
"dependencies": {
40-
"github.com/sdboyer/gps": {
41-
"version": "^v0.12.0"
42-
},
4341
"github.com/babble/brook": {
4442
"revision": "d05d5aca9f895d19e9265839bffeadd74a2d2ecb"
43+
},
44+
"github.com/sdboyer/gps": {
45+
"version": ">=0.12.0, <1.0.0"
4546
}
4647
},
4748
"overrides": {
@@ -55,6 +56,7 @@ func TestReadManifest(t *testing.T) {
5556
]
5657
}`
5758

59+
func TestReadManifest(t *testing.T) {
5860
_, err := readManifest(strings.NewReader(je))
5961
if err == nil {
6062
t.Error("Reading manifest with invalid props should have caused error, but did not")
@@ -67,7 +69,7 @@ func TestReadManifest(t *testing.T) {
6769
t.Fatalf("Should have read Manifest correctly, but got err %q", err)
6870
}
6971

70-
c, _ := gps.NewSemverConstraint("^v0.12.0")
72+
c, _ := gps.NewSemverConstraint(">=0.12.0, <1.0.0")
7173
em := manifest{
7274
Dependencies: map[gps.ProjectRoot]gps.ProjectProperties{
7375
gps.ProjectRoot("github.com/sdboyer/gps"): {
@@ -96,3 +98,42 @@ func TestReadManifest(t *testing.T) {
9698
t.Error("Valid manifest's ignores did not parse as expected")
9799
}
98100
}
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

Comments
 (0)