-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlicense_test.go
More file actions
59 lines (53 loc) · 1.56 KB
/
Copy pathlicense_test.go
File metadata and controls
59 lines (53 loc) · 1.56 KB
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
package cinc
import (
"context"
"testing"
"github.com/tas50/cinc-api/internal/cinctest"
)
func TestLicense_Get(t *testing.T) {
srv := cinctest.New(t)
srv.Handle("GET /license", cinctest.Route{
Body: `{"limit_exceeded":false,"node_license":25,"node_count":5,"upgrade_url":"https://www.chef.io/contact-us"}`,
})
c := newTestClient(t, srv.Server)
lic, _, err := c.License.Get(context.Background())
if err != nil {
t.Fatalf("Get: %v", err)
}
if lic.LimitExceeded {
t.Errorf("LimitExceeded = true, want false")
}
if lic.NodeLicense != 25 || lic.NodeCount != 5 {
t.Errorf("license counts = %+v", lic)
}
if lic.UpgradeURL == "" {
t.Errorf("UpgradeURL is empty")
}
}
func TestLicense_LimitExceeded(t *testing.T) {
srv := cinctest.New(t)
srv.Handle("GET /license", cinctest.Route{
Body: `{"limit_exceeded":true,"node_license":25,"node_count":42,"upgrade_url":"https://www.chef.io/contact-us"}`,
})
c := newTestClient(t, srv.Server)
lic, _, err := c.License.Get(context.Background())
if err != nil {
t.Fatalf("Get: %v", err)
}
if !lic.LimitExceeded {
t.Error("LimitExceeded = false, want true")
}
if lic.NodeCount <= lic.NodeLicense {
t.Errorf("expected NodeCount (%d) to exceed NodeLicense (%d)", lic.NodeCount, lic.NodeLicense)
}
}
func TestLicense_Error(t *testing.T) {
srv := cinctest.New(t)
srv.Handle("GET /license", cinctest.Route{
Status: 500, Body: `{"error":["license server unavailable"]}`,
})
c := newTestClient(t, srv.Server)
if _, _, err := c.License.Get(context.Background()); err == nil {
t.Fatal("expected error from 500")
}
}