-
Notifications
You must be signed in to change notification settings - Fork 64
/
status_test.go
80 lines (70 loc) · 2.08 KB
/
status_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
package chef
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
"reflect"
"testing"
)
var (
testStatusJSON = "test/status.json"
)
func TestStatusFromJSONDecoder(t *testing.T) {
if file, err := os.Open(testStatusJSON); err != nil {
t.Error("Unexpected error '", err, "' during os.Open on", testStatusJSON)
} else {
dec := json.NewDecoder(file)
var g Status
if err := dec.Decode(&g); err == io.EOF {
log.Fatal(g)
} else if err != nil {
log.Fatal(err)
}
}
}
func TestStatusGet(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/_status", func(w http.ResponseWriter, r *http.Request) {
dec := json.NewDecoder(r.Body)
var request Status
dec.Decode(&request)
switch {
case r.Method == "GET":
fmt.Fprintf(w, `{
"status": "pong",
"upstreams": {
"chef_elasticsearch": "pong",
"chef_sql": "pong",
"chef_index": "pong",
"oc_chef_authz": "pong",
"data_collector": "pong"
},
"keygen": {
"keys": 10,
"max": 10,
"max_workers": 2,
"cur_max_workers": 2,
"inflight": 0,
"avail_workers": 2,
"start_size": 0
}
}`)
}
})
wantStatus := Status{
Status: "pong",
Upstreams: map[string]string{"chef_elasticsearch": "pong", "chef_index": "pong", "chef_sql": "pong", "data_collector": "pong", "oc_chef_authz": "pong"},
Keygen: map[string]int{"avail_workers": 2, "cur_max_workers": 2, "inflight": 0, "keys": 10, "max": 10, "max_workers": 2, "start_size": 0},
}
status, err := client.Status.Get()
if err != nil {
t.Errorf("Status.Get returned error: %s", err.Error())
}
if !reflect.DeepEqual(status, wantStatus) {
t.Errorf("Status.Get returned %+v, want %+v, error %+v", status, wantStatus, err)
}
}