-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathbilling_budgets_test.go
More file actions
166 lines (147 loc) · 4.42 KB
/
billing_budgets_test.go
File metadata and controls
166 lines (147 loc) · 4.42 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright 2026 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"fmt"
"net/http"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestBillingService_ListOrganizationBudgets(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/organizations/o/settings/billing/budgets", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{
"budgets": [
{
"id": "1",
"budget_name": "Budget 1",
"limit_amount": 100.5,
"budget_alerting": {
"will_alert": true,
"alert_recipients": ["user1"]
}
}
]
}`)
})
ctx := t.Context()
budgets, _, err := client.Billing.ListOrganizationBudgets(ctx, "o")
if err != nil {
t.Errorf("Billing.ListOrganizationBudgets returned error: %v", err)
}
want := &BudgetList{
Budgets: []*Budget{
{
ID: Ptr("1"),
BudgetName: Ptr("Budget 1"),
LimitAmount: Ptr(100.5),
BudgetAlerting: &BudgetAlerting{
WillAlert: Ptr(true),
AlertRecipients: []string{"user1"},
},
},
},
}
if !cmp.Equal(budgets, want) {
t.Errorf("Billing.ListOrganizationBudgets returned %+v, want %+v", budgets, want)
}
const methodName = "ListOrganizationBudgets"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Billing.ListOrganizationBudgets(ctx, "o")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestBillingService_GetOrganizationBudget(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/organizations/o/settings/billing/budgets/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{
"id": "1",
"budget_name": "Budget 1"
}`)
})
ctx := t.Context()
budget, _, err := client.Billing.GetOrganizationBudget(ctx, "o", "1")
if err != nil {
t.Errorf("Billing.GetOrganizationBudget returned error: %v", err)
}
want := &Budget{
ID: Ptr("1"),
BudgetName: Ptr("Budget 1"),
}
if !cmp.Equal(budget, want) {
t.Errorf("Billing.GetOrganizationBudget returned %+v, want %+v", budget, want)
}
const methodName = "GetOrganizationBudget"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Billing.GetOrganizationBudget(ctx, "o", "1")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestBillingService_UpdateOrganizationBudget(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
input := &Budget{
BudgetName: Ptr("Updated Budget"),
}
mux.HandleFunc("/organizations/o/settings/billing/budgets/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
testBody(t, r, `{"budget_name":"Updated Budget"}`+"\n")
fmt.Fprint(w, `{
"budget": {
"id": "1",
"budget_name": "Updated Budget"
}
}`)
})
ctx := t.Context()
budget, _, err := client.Billing.UpdateOrganizationBudget(ctx, "o", "1", input)
if err != nil {
t.Errorf("Billing.UpdateOrganizationBudget returned error: %v", err)
}
want := &BudgetResponse{
Budget: &Budget{
ID: Ptr("1"),
BudgetName: Ptr("Updated Budget"),
},
}
if !cmp.Equal(budget, want) {
t.Errorf("Billing.UpdateOrganizationBudget returned %+v, want %+v", budget, want)
}
const methodName = "UpdateOrganizationBudget"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Billing.UpdateOrganizationBudget(ctx, "o", "1", input)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestBillingService_DeleteOrganizationBudget(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/organizations/o/settings/billing/budgets/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusNoContent)
})
ctx := t.Context()
_, err := client.Billing.DeleteOrganizationBudget(ctx, "o", "1")
if err != nil {
t.Errorf("Billing.DeleteOrganizationBudget returned error: %v", err)
}
const methodName = "DeleteOrganizationBudget"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Billing.DeleteOrganizationBudget(ctx, "o", "1")
})
}