-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_test.go
100 lines (81 loc) · 2.58 KB
/
run_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
package scalr
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRunsRead(t *testing.T) {
client := testClient(t)
ctx := context.Background()
runTest, runTestCleanup := createRun(t, client, nil, nil)
defer runTestCleanup()
t.Run("when the run exists", func(t *testing.T) {
_, err := client.Runs.Read(ctx, runTest.ID)
assert.NoError(t, err)
})
t.Run("when the run does not exist", func(t *testing.T) {
var runId = "nonexisting"
r, err := client.Runs.Read(ctx, runId)
assert.Nil(t, r)
assert.Equal(
t,
ResourceNotFoundError{
Message: fmt.Sprintf("Run with ID '%s' not found or user unauthorized.", runId),
}.Error(),
err.Error(),
)
})
t.Run("with invalid run ID", func(t *testing.T) {
r, err := client.Runs.Read(ctx, badIdentifier)
assert.Nil(t, r)
assert.EqualError(t, err, "invalid value for run ID")
})
}
func TestRunsCreate(t *testing.T) {
client := testClient(t)
ctx := context.Background()
wsTest, wsTestCleanup := createWorkspace(t, client, nil)
defer wsTestCleanup()
cvTest, _ := createConfigurationVersion(t, client, wsTest)
t.Run("without a configuration version", func(t *testing.T) {
options := RunCreateOptions{
Workspace: wsTest,
}
_, err := client.Runs.Create(ctx, options)
assert.EqualError(t, err, "Invalid Relationship\n\nNo configuration versions available to create the run from. Upload at least one or link the workspace to a VCS provider.")
})
t.Run("with invalid configuration-version ID", func(t *testing.T) {
options := RunCreateOptions{
ConfigurationVersion: &ConfigurationVersion{ID: badIdentifier},
Workspace: wsTest,
}
r, err := client.Runs.Create(ctx, options)
assert.Nil(t, r)
assert.EqualError(t, err, "invalid value for configuration-version ID")
})
t.Run("without a workspace", func(t *testing.T) {
r, err := client.Runs.Create(ctx, RunCreateOptions{})
assert.Nil(t, r)
assert.EqualError(t, err, "workspace is required")
})
t.Run("with invalid workspace ID", func(t *testing.T) {
options := RunCreateOptions{
ConfigurationVersion: cvTest,
Workspace: &Workspace{ID: badIdentifier},
}
r, err := client.Runs.Create(ctx, options)
assert.Nil(t, r)
assert.EqualError(t, err, "invalid value for workspace ID")
})
t.Run("with valid options", func(t *testing.T) {
options := RunCreateOptions{
ConfigurationVersion: cvTest,
Workspace: wsTest,
}
r, err := client.Runs.Create(ctx, options)
require.NoError(t, err)
assert.Equal(t, cvTest.ID, r.ConfigurationVersion.ID)
})
}