-
Notifications
You must be signed in to change notification settings - Fork 56
/
budget_test.go
111 lines (102 loc) · 2.03 KB
/
budget_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
109
110
111
package gads
import (
"testing"
)
func testBudgetService(t *testing.T) (service *BudgetService) {
return &BudgetService{Auth: testAuthSetup(t)}
}
func testBudget(t *testing.T) (Budget, func()) {
s := testBudgetService(t)
budgets, err := s.Mutate(
BudgetOperations{
"ADD": {
Budget{
Name: "testbudget " + rand_str(10),
Period: "DAILY",
Amount: 50000000,
Delivery: "STANDARD",
},
},
},
)
if err != nil {
t.Fatal(err)
}
cleanupBudget := func() {
_, err = s.Mutate(BudgetOperations{"REMOVE": budgets})
if err != nil {
t.Error(err)
}
}
return budgets[0], cleanupBudget
}
func TestBudget(t *testing.T) {
s := testBudgetService(t)
budgets, err := s.Mutate(
BudgetOperations{
"ADD": {
Budget{
Name: "testbudget " + rand_str(10),
Period: "DAILY",
Amount: 50000000,
Delivery: "STANDARD",
},
Budget{
Name: "test budget " + rand_str(10),
Period: "DAILY",
Amount: 50000000,
Delivery: "STANDARD",
},
},
},
)
if err != nil {
t.Fatal(err)
}
defer func(bs []Budget) {
_, err = s.Mutate(BudgetOperations{"REMOVE": bs})
if err != nil {
t.Error(err)
}
}(budgets)
foundBudgets, _, err := s.Get(
Selector{
Fields: []string{
"BudgetId",
"BudgetName",
"Period",
"Amount",
"DeliveryMethod",
"BudgetReferenceCount",
"IsBudgetExplicitlyShared",
"BudgetStatus",
},
Predicates: []Predicate{
{"Amount", "LESS_THAN_EQUALS", []string{"500000000"}},
{"BudgetStatus", "EQUALS", []string{"ENABLED"}},
},
Ordering: []OrderBy{
{"BudgetId", "ASCENDING"},
{"Amount", "ASCENDING"},
},
Paging: &Paging{
Offset: 0,
Limit: 100,
},
},
)
if err != nil {
t.Fatal(err)
}
t.Logf("found %d budgets\n", len(foundBudgets))
for _, b := range budgets {
func(budget Budget) {
for _, foundBudget := range foundBudgets {
if foundBudget.Id == budget.Id {
return
}
}
t.Errorf("budget %d not found in \n%#v\n", budget.Id, foundBudgets)
}(b)
}
}