-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon_operations_vcr_test.go
More file actions
156 lines (127 loc) · 3.99 KB
/
common_operations_vcr_test.go
File metadata and controls
156 lines (127 loc) · 3.99 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
package client
import (
"net/http"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/dnaeon/go-vcr.v2/cassette"
"gopkg.in/dnaeon/go-vcr.v2/recorder"
)
// TestListInstancesVCR tests listing all instances
func TestListInstancesVCR(t *testing.T) {
r, err := recorder.New("fixtures/list_instances")
if err != nil {
t.Fatal(err)
}
defer r.Stop()
// Add sanitization filters
r.AddFilter(func(i *cassette.Interaction) error {
delete(i.Request.Headers, "Authorization")
i.Response.Body = sanitizeResponseBody(i.Response.Body)
delete(i.Response.Headers, "Set-Cookie")
return nil
})
apiKey := os.Getenv("CLOUDAMQP_APIKEY")
if apiKey == "" {
apiKey = "vcr-replay-mode"
}
httpClient := &http.Client{Transport: r}
client := NewWithHTTPClient(apiKey, "https://customer.cloudamqp.com/api", "test", httpClient)
instances, err := client.ListInstances()
require.NoError(t, err)
require.NotNil(t, instances)
// Should have at least some instances (or empty list is OK)
t.Logf("✓ Listed %d instances", len(instances))
}
// TestGetInstanceVCR tests getting a specific instance
func TestGetInstanceVCR(t *testing.T) {
r, err := recorder.New("fixtures/get_instance")
if err != nil {
t.Fatal(err)
}
defer r.Stop()
r.AddFilter(func(i *cassette.Interaction) error {
delete(i.Request.Headers, "Authorization")
i.Response.Body = sanitizeResponseBody(i.Response.Body)
delete(i.Response.Headers, "Set-Cookie")
return nil
})
apiKey := os.Getenv("CLOUDAMQP_APIKEY")
if apiKey == "" {
apiKey = "vcr-replay-mode"
}
httpClient := &http.Client{Transport: r}
client := NewWithHTTPClient(apiKey, "https://customer.cloudamqp.com/api", "test", httpClient)
// Use an existing instance ID (should match cassette)
instanceID := 359563
instance, err := client.GetInstance(instanceID)
require.NoError(t, err)
require.NotNil(t, instance)
assert.Equal(t, instanceID, instance.ID)
t.Logf("✓ Got instance %d: %s (plan: %s)", instance.ID, instance.Name, instance.Plan)
}
// TestListRegionsVCR tests listing all regions
func TestListRegionsVCR(t *testing.T) {
r, err := recorder.New("fixtures/list_regions")
if err != nil {
t.Fatal(err)
}
defer r.Stop()
r.AddFilter(func(i *cassette.Interaction) error {
delete(i.Request.Headers, "Authorization")
i.Response.Body = sanitizeResponseBody(i.Response.Body)
delete(i.Response.Headers, "Set-Cookie")
return nil
})
apiKey := os.Getenv("CLOUDAMQP_APIKEY")
if apiKey == "" {
apiKey = "vcr-replay-mode"
}
httpClient := &http.Client{Transport: r}
client := NewWithHTTPClient(apiKey, "https://customer.cloudamqp.com/api", "test", httpClient)
regions, err := client.ListRegions("")
require.NoError(t, err)
require.NotEmpty(t, regions)
t.Logf("✓ Listed %d regions", len(regions))
// Verify some expected fields
if len(regions) > 0 {
assert.NotEmpty(t, regions[0].Name)
assert.NotEmpty(t, regions[0].Provider)
t.Logf(" Example: %s (%s)", regions[0].Name, regions[0].Provider)
}
}
// TestListPlansVCR tests listing all plans
func TestListPlansVCR(t *testing.T) {
r, err := recorder.New("fixtures/list_plans")
if err != nil {
t.Fatal(err)
}
defer r.Stop()
r.AddFilter(func(i *cassette.Interaction) error {
delete(i.Request.Headers, "Authorization")
i.Response.Body = sanitizeResponseBody(i.Response.Body)
delete(i.Response.Headers, "Set-Cookie")
return nil
})
apiKey := os.Getenv("CLOUDAMQP_APIKEY")
if apiKey == "" {
apiKey = "vcr-replay-mode"
}
httpClient := &http.Client{Transport: r}
client := NewWithHTTPClient(apiKey, "https://customer.cloudamqp.com/api", "test", httpClient)
plans, err := client.ListPlans("")
require.NoError(t, err)
require.NotEmpty(t, plans)
t.Logf("✓ Listed %d plans", len(plans))
// Verify some expected fields and find bunny-1
bunnyFound := false
for _, plan := range plans {
assert.NotEmpty(t, plan.Name)
if plan.Name == "bunny-1" {
bunnyFound = true
t.Logf(" Found bunny-1 plan")
}
}
assert.True(t, bunnyFound, "Should find bunny-1 plan")
}