-
Notifications
You must be signed in to change notification settings - Fork 64
/
license_test.go
66 lines (58 loc) · 1.4 KB
/
license_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
package chef
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
"reflect"
"testing"
)
var (
testLicenseJSON = "test/license.json"
)
func TestLicenseFromJSONDecoder(t *testing.T) {
if file, err := os.Open(testLicenseJSON); err != nil {
t.Error("Unexpected error '", err, "' during os.Open on", testLicenseJSON)
} else {
dec := json.NewDecoder(file)
var g License
if err := dec.Decode(&g); err == io.EOF {
log.Fatal(g)
} else if err != nil {
log.Fatal(err)
}
}
}
func TestLicenseGet(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/license", func(w http.ResponseWriter, r *http.Request) {
dec := json.NewDecoder(r.Body)
var request License
dec.Decode(&request)
switch {
case r.Method == "GET":
fmt.Fprintf(w, `{
"limit_exceeded": false,
"node_license": 25,
"node_count": 12,
"upgrade_url": "http://www.chef.io/contact/on-premises-simple"
}`)
}
})
wantLicense := License{
LimitExceeded: false,
NodeLicense: 25,
NodeCount: 12,
UpgradeUrl: "http://www.chef.io/contact/on-premises-simple",
}
license, err := client.License.Get()
if err != nil {
t.Errorf("License.Get returned error: %s", err.Error())
}
if !reflect.DeepEqual(license, wantLicense) {
t.Errorf("License.Get returned %+v, want %+v", license, wantLicense)
}
}