This repository has been archived by the owner on Aug 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
resource_groups_test.go
74 lines (64 loc) · 2.55 KB
/
resource_groups_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
package insightcloudsec
import (
"encoding/json"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestResourceGroups_Create(t *testing.T) {
setup()
mux.HandleFunc("/v2/public/resourcegroup/create", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method)
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, getJSONFile("resourceGroups/createResourceGroupResponse.json"))
})
resp, err := client.ResourceGroups.Create("Test Resource Group", "Would you believe it's for grouping things?")
assert.NoError(t, err)
assert.Equal(t, "resourcegroup:3:", resp.ID)
assert.Equal(t, "Test Resource Group", resp.Name)
assert.Equal(t, 3, resp.ResourceGroupID)
assert.Equal(t, "Would you believe it's for grouping things?", resp.Description)
assert.Equal(t, "system", resp.Category)
assert.Equal(t, "2022-04-10 05:59:34", resp.CreationTime)
assert.Equal(t, "user", resp.GroupType)
assert.Equal(t, "organization", resp.OwnerType)
assert.Equal(t, []string{}, resp.NestedResourceGroups)
teardown()
}
func TestResourceGroups_AddToGroup(t *testing.T) {
setup()
mux.HandleFunc("/v2/prototype/resourcegroups/resources/add", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method)
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusOK)
var req ResourcesToGroup
err := json.NewDecoder(r.Body).Decode(&req)
assert.NoError(t, err)
assert.Equal(t, req, ResourcesToGroup{
ResourceIDs: []string{"instance:20:us-east-1:i-0000a0b11cd33e4:"},
ResourceGroupIDs: []string{"resourcegroup:3:"},
})
})
err := client.ResourceGroups.AddToGroup([]string{"instance:20:us-east-1:i-0000a0b11cd33e4:"}, "resourcegroup:3:")
assert.NoError(t, err)
teardown()
}
func TestResourceGroups_Delete(t *testing.T) {
setup()
mux.HandleFunc("/v2/prototype/resources/delete", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method)
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusOK)
var req ResourceGroupIDsList
err := json.NewDecoder(r.Body).Decode(&req)
assert.NoError(t, err)
assert.Equal(t, req, ResourceGroupIDsList{
ResourceIDs: []string{"instance:20:us-east-1:i-0000a0b11cd33e4:"},
})
})
err := client.ResourceGroups.Delete([]string{"instance:20:us-east-1:i-0000a0b11cd33e4:"})
assert.NoError(t, err)
teardown()
}