This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
plans_test.go
98 lines (82 loc) · 2.1 KB
/
plans_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
98
package packngo
import (
"log"
"testing"
)
func plansInFacilities(t *testing.T, plans []Plan) {
if len(plans) == 0 {
t.Fatal("Empty plans listing from the API")
}
avail := map[string][]string{}
for _, p := range plans {
for _, f := range p.AvailableIn {
if _, ok := avail[f.Code]; !ok {
avail[f.Code] = []string{p.Slug}
} else {
avail[f.Code] = append(avail[f.Code], p.Slug)
}
}
if p.Pricing.Hour < 0.0 {
t.Fatalf("Strange pricing for %s %s", p.Name, p.Slug)
}
}
for f, ps := range avail {
if len(ps) == 0 {
t.Fatalf("no plans available in facility %s", f)
}
// prints plans available in facility
log.Printf("%s: %+v\n", f, ps)
}
}
func TestAccPlansFilter(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, stopRecord := setup(t)
defer stopRecord()
opts := &ListOptions{Includes: []string{"available_in"}}
optsOnDemand := opts.Filter("deployment_type", "on_demand")
onDemandPlans, _, err := c.Plans.List(optsOnDemand)
if err != nil {
t.Fatal(err)
}
allPlans, _, err := c.Plans.List(opts)
if err != nil {
t.Fatal(err)
}
if len(onDemandPlans) >= len(allPlans) {
t.Fatalf("filtering of plans listing might not be working")
}
}
func TestAccPlansBasic(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, stopRecord := setup(t)
defer stopRecord()
l, _, err := c.Plans.List(&ListOptions{Includes: []string{"available_in"}})
if err != nil {
t.Fatal(err)
}
plansInFacilities(t, l)
}
func TestAccPlansProject(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, projectID, teardown := setupWithProject(t)
defer teardown()
l, _, err := c.Plans.ProjectList(projectID, &ListOptions{Includes: []string{"available_in"}})
if err != nil {
t.Fatal(err)
}
plansInFacilities(t, l)
}
func TestAccPlansOrganization(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, stopRecord := setup(t)
defer stopRecord()
user, _, err := c.Users.Current()
if err != nil {
t.Fatal(err)
}
l, _, err := c.Plans.OrganizationList(user.DefaultOrganizationID, &ListOptions{Includes: []string{"available_in"}})
if err != nil {
t.Fatal(err)
}
plansInFacilities(t, l)
}