forked from aiven/aiven-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbilling_group_acc_test.go
108 lines (92 loc) · 3.09 KB
/
billing_group_acc_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
99
100
101
102
103
104
105
106
107
108
package aiven
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"math/rand"
"strconv"
)
var _ = Describe("BillingGroup", func() {
var (
billingGName string
billingG *BillingGroup
err error
)
BeforeEach(func() {
billingGName = "test-acc-bg-" + strconv.Itoa(rand.Int())
billingG, err = client.BillingGroup.Create(BillingGroupRequest{
BillingGroupName: billingGName,
Company: ToStringPointer("testC1"),
AddressLines: []string{"NYC Some Street 123 A"},
CountryCode: ToStringPointer("US"),
City: ToStringPointer("NY"),
ZipCode: ToStringPointer("101778"),
BillingCurrency: ToStringPointer("EUR"),
})
})
Context("Billing group tests", func() {
It("should not error", func() {
Expect(err).NotTo(HaveOccurred())
})
It("should populate fields properly", func() {
Expect(billingG).NotTo(BeNil())
if billingG != nil {
Expect(*billingG.Company).NotTo(BeEmpty())
Expect(billingG.AddressLines).NotTo(BeEmpty())
Expect(*billingG.CountryCode).NotTo(BeEmpty())
Expect(*billingG.City).NotTo(BeEmpty())
Expect(*billingG.ZipCode).NotTo(BeEmpty())
Expect(*billingG.BillingCurrency).NotTo(BeEmpty())
Expect(billingG.BillingGroupName).NotTo(BeEmpty())
}
})
It("update and get checks", func() {
_, err = client.BillingGroup.Update(billingG.Id, BillingGroupRequest{
BillingExtraText: ToStringPointer("some text ..."),
})
Expect(err).NotTo(HaveOccurred())
billingG, err = client.BillingGroup.Get(billingG.Id)
Expect(err).NotTo(HaveOccurred())
if billingG != nil {
Expect(*billingG.Company).NotTo(BeEmpty())
Expect(billingG.AddressLines).NotTo(BeEmpty())
Expect(*billingG.CountryCode).NotTo(BeEmpty())
Expect(*billingG.City).NotTo(BeEmpty())
Expect(*billingG.ZipCode).NotTo(BeEmpty())
Expect(*billingG.BillingCurrency).NotTo(BeEmpty())
Expect(billingG.BillingGroupName).NotTo(BeEmpty())
Expect(*billingG.BillingExtraText).NotTo(BeEmpty())
}
})
It("check empty assigned projects list", func() {
projects, err := client.BillingGroup.GetProjects(billingG.Id)
Expect(err).NotTo(HaveOccurred())
Expect(projects).To(BeEmpty())
})
It("assign a project", func() {
projectName := "test-acc-pr-" + strconv.Itoa(rand.Int())
_, err = client.Projects.Create(CreateProjectRequest{
Project: projectName,
VatID: ToStringPointer(""),
})
Expect(err).NotTo(HaveOccurred())
err = client.BillingGroup.AssignProjects(billingG.Id, []string{projectName})
Expect(err).NotTo(HaveOccurred())
projects, errG := client.BillingGroup.GetProjects(billingG.Id)
Expect(errG).NotTo(HaveOccurred())
Expect(projects).NotTo(BeEmpty())
err = client.Projects.Delete(projectName)
Expect(err).NotTo(HaveOccurred())
})
It("list all billing groups", func() {
list, err := client.BillingGroup.ListAll()
Expect(err).NotTo(HaveOccurred())
Expect(list).NotTo(BeEmpty())
})
})
AfterEach(func() {
err = client.BillingGroup.Delete(billingG.Id)
if err != nil {
Fail("cannot delete billing group : " + err.Error())
}
})
})