-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinfracost_integration_test.go
111 lines (94 loc) · 2.93 KB
/
infracost_integration_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 scalr
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"
)
func TestInfracostIntegrations_Create(t *testing.T) {
client := testClient(t)
ctx := context.Background()
apiKey := os.Getenv("TEST_INFRACOST_API_KEY")
if len(apiKey) == 0 {
t.Skip("Please set TEST_INFRACOST_API_KEY to run this test.")
}
t.Run("with valid options", func(t *testing.T) {
options := InfracostIntegrationCreateOptions{
Name: String("test-" + randomString(t)),
ApiKey: &apiKey,
}
ii, err := client.InfracostIntegrations.Create(ctx, options)
require.NoError(t, err)
defer func() { client.InfracostIntegrations.Delete(ctx, ii.ID) }()
refreshed, err := client.InfracostIntegrations.Read(ctx, ii.ID)
require.NoError(t, err)
for _, item := range []*InfracostIntegration{
ii,
refreshed,
} {
assert.NotEmpty(t, item.ID)
assert.Equal(t, *options.Name, item.Name)
assert.Empty(t, item.ApiKey)
}
})
}
func TestInfracostIntegrations_Update(t *testing.T) {
client := testClient(t)
ctx := context.Background()
apiKey := os.Getenv("TEST_INFRACOST_API_KEY")
if len(apiKey) == 0 {
t.Skip("Please set TEST_INFRACOST_API_KEY to run this test.")
}
createOptions := InfracostIntegrationCreateOptions{
Name: String("test-" + randomString(t)),
ApiKey: &apiKey,
}
ii, err := client.InfracostIntegrations.Create(ctx, createOptions)
require.NoError(t, err)
defer func() { client.InfracostIntegrations.Delete(ctx, ii.ID) }()
t.Run("with valid options", func(t *testing.T) {
options := InfracostIntegrationUpdateOptions{
Name: String("test-" + randomString(t)),
ApiKey: &apiKey,
//Status: IntegrationStatusDisabled,
}
ii, err := client.InfracostIntegrations.Update(ctx, ii.ID, options)
require.NoError(t, err)
refreshed, err := client.InfracostIntegrations.Read(ctx, ii.ID)
require.NoError(t, err)
for _, item := range []*InfracostIntegration{
ii,
refreshed,
} {
assert.NotEmpty(t, item.ID)
assert.Equal(t, *options.Name, item.Name)
}
})
}
func TestInfracostIntegrations_List(t *testing.T) {
client := testClient(t)
ctx := context.Background()
apiKey := os.Getenv("TEST_INFRACOST_API_KEY")
if len(apiKey) == 0 {
t.Skip("Please set TEST_INFRACOST_API_KEY to run this test.")
}
createOptions := InfracostIntegrationCreateOptions{
Name: String("test-" + randomString(t)),
ApiKey: &apiKey,
}
ii, err := client.InfracostIntegrations.Create(ctx, createOptions)
require.NoError(t, err)
defer func() { client.InfracostIntegrations.Delete(ctx, ii.ID) }()
t.Run("with valid options", func(t *testing.T) {
iil, err := client.InfracostIntegrations.List(ctx, InfracostIntegrationListOptions{})
require.NoError(t, err)
assert.Equal(t, 1, iil.TotalCount)
expectedIDs := []string{ii.ID}
actualIDs := make([]string, len(iil.Items))
for i, s := range iil.Items {
actualIDs[i] = s.ID
}
assert.ElementsMatch(t, expectedIDs, actualIDs)
})
}