-
Notifications
You must be signed in to change notification settings - Fork 65
/
universe_test.go
97 lines (91 loc) · 2.51 KB
/
universe_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
package chef
import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestUniverseGet(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/universe", func(w http.ResponseWriter, r *http.Request) {
dec := json.NewDecoder(r.Body)
var request Universe
dec.Decode(&request)
switch {
case r.Method == "GET":
fmt.Fprintf(w, `{
"ffmpeg": {
"0.1.0": {
"location_path": "http://supermarket.chef.io/api/v1/cookbooks/ffmpeg/0.1.0/download",
"location_type": "supermarket",
"dependencies": {
"git": ">= 0.0.0",
"build-essential": ">= 0.0.0",
"libvpx": "~> 0.1.1",
"x264": "~> 0.1.1"
}
},
"0.1.1": {
"location_path": "http://supermarket.chef.io/api/v1/cookbooks/ffmpeg/0.1.1/download",
"location_type": "supermarket",
"dependencies": {
"git": ">= 0.0.0",
"build-essential": ">= 0.0.0",
"libvpx": "~> 0.1.1",
"x264": "~> 0.1.1"
}
}
},
"pssh": {
"0.1.0": {
"location_path": "http://supermarket.chef.io/api/v1/cookbooks/pssh.1.0/download",
"location_type": "supermarket",
"dependencies": {}
}
}
}`)
}
})
wantU := Universe{}
wantU.Books = make(map[string]UniverseBook)
ffmpeg := UniverseBook{}
ffmpeg.Versions = make(map[string]UniverseVersion)
ffmpeg.Versions["0.1.0"] = UniverseVersion{
LocationPath: "http://supermarket.chef.io/api/v1/cookbooks/ffmpeg/0.1.0/download",
LocationType: "supermarket",
Dependencies: map[string]string{
"git": ">= 0.0.0",
"build-essential": ">= 0.0.0",
"libvpx": "~> 0.1.1",
"x264": "~> 0.1.1",
},
}
ffmpeg.Versions["0.1.1"] = UniverseVersion{
LocationPath: "http://supermarket.chef.io/api/v1/cookbooks/ffmpeg/0.1.1/download",
LocationType: "supermarket",
Dependencies: map[string]string{
"git": ">= 0.0.0",
"build-essential": ">= 0.0.0",
"libvpx": "~> 0.1.1",
"x264": "~> 0.1.1",
},
}
pssh := UniverseBook{}
pssh.Versions = make(map[string]UniverseVersion)
pssh.Versions["0.1.0"] = UniverseVersion{
LocationPath: "http://supermarket.chef.io/api/v1/cookbooks/pssh.1.0/download",
LocationType: "supermarket",
Dependencies: map[string]string{},
}
wantU.Books["ffmpeg"] = ffmpeg
wantU.Books["pssh"] = pssh
universe, err := client.Universe.Get()
if err != nil {
t.Errorf("Universe.Get returned error: %s", err.Error())
}
if !reflect.DeepEqual(universe, wantU) {
t.Errorf("Universe.Get returned %+v, want %+v", universe, wantU)
}
}