-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfiguration_version_test.go
76 lines (64 loc) · 2.14 KB
/
configuration_version_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
package scalr
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestConfigurationVersionsCreate(t *testing.T) {
client := testClient(t)
ctx := context.Background()
wsTest, wsTestCleanup := createWorkspace(t, client, nil)
defer wsTestCleanup()
t.Run("with valid options", func(t *testing.T) {
cv, err := client.ConfigurationVersions.Create(ctx,
ConfigurationVersionCreateOptions{Workspace: wsTest},
)
require.NoError(t, err)
// Get a refreshed view of the configuration version.
refreshed, err := client.ConfigurationVersions.Read(ctx, cv.ID)
require.NoError(t, err)
assert.Equal(t, cv, refreshed)
})
t.Run("when no workspace is provided", func(t *testing.T) {
_, err := client.ConfigurationVersions.Create(ctx, ConfigurationVersionCreateOptions{})
assert.EqualError(t, err, "workspace is required")
})
t.Run("with invalid workspace id", func(t *testing.T) {
cv, err := client.ConfigurationVersions.Create(
ctx,
ConfigurationVersionCreateOptions{Workspace: &Workspace{ID: badIdentifier}},
)
assert.Nil(t, cv)
assert.EqualError(t, err, "invalid value for workspace ID")
})
}
func TestConfigurationVersionsRead(t *testing.T) {
client := testClient(t)
ctx := context.Background()
cvTest, cvCleanup := createConfigurationVersion(t, client, nil)
defer cvCleanup()
t.Run("when the configuration version exists", func(t *testing.T) {
cv, err := client.ConfigurationVersions.Read(ctx, cvTest.ID)
require.NoError(t, err)
assert.Equal(t, cvTest, cv)
})
t.Run("when the configuration version does not exist", func(t *testing.T) {
var cvName = "nonexisting"
cv, err := client.ConfigurationVersions.Read(ctx, cvName)
assert.Nil(t, cv)
assert.Equal(
t,
ResourceNotFoundError{
Message: fmt.Sprintf("ConfigurationVersion with ID '%s' not found or user unauthorized.", cvName),
}.Error(),
err.Error(),
)
})
t.Run("with invalid configuration version id", func(t *testing.T) {
cv, err := client.ConfigurationVersions.Read(ctx, badIdentifier)
assert.Nil(t, cv)
assert.EqualError(t, err, "invalid value for configuration version ID")
})
}