forked from hashicorp/go-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_version_output_integration_test.go
81 lines (62 loc) · 1.96 KB
/
state_version_output_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
//go:build integration
// +build integration
package tfe
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStateVersionOutputsRead(t *testing.T) {
client := testClient(t)
ctx := context.Background()
wTest1, wTest1Cleanup := createWorkspace(t, client, nil)
defer wTest1Cleanup()
svTest, svTestCleanup := createStateVersion(t, client, 0, wTest1)
defer svTestCleanup()
// give TFC some time to process the statefile and extract the outputs.
waitForSVOutputs(t, client, svTest.ID)
curOpts := &StateVersionCurrentOptions{
Include: []StateVersionIncludeOpt{SVoutputs},
}
sv, err := client.StateVersions.ReadCurrentWithOptions(ctx, wTest1.ID, curOpts)
if err != nil {
t.Fatal(err)
}
output := sv.Outputs[0]
t.Run("Read by ID", func(t *testing.T) {
t.Run("when a state output exists", func(t *testing.T) {
so, err := client.StateVersionOutputs.Read(ctx, output.ID)
require.NoError(t, err)
assert.Equal(t, so.ID, output.ID)
assert.Equal(t, so.Name, output.Name)
assert.Equal(t, so.Value, output.Value)
})
t.Run("when a state output does not exist", func(t *testing.T) {
so, err := client.StateVersionOutputs.Read(ctx, "wsout-J2zM24JPAAAAAAAA")
assert.Nil(t, so)
assert.Equal(t, ErrResourceNotFound, err)
})
})
t.Run("Read current workspace outputs", func(t *testing.T) {
so, err := client.StateVersionOutputs.ReadCurrent(ctx, wTest1.ID)
assert.Nil(t, err)
assert.NotNil(t, so)
assert.Greater(t, len(so.Items), 0, "workspace state version outputs were empty")
})
t.Run("Sensitive secrets are null", func(t *testing.T) {
so, err := client.StateVersionOutputs.ReadCurrent(ctx, wTest1.ID)
assert.Nil(t, err)
assert.NotNil(t, so)
var found *StateVersionOutput = nil
for _, s := range so.Items {
if s.Name == "test_output_string" {
found = s
break
}
}
assert.NotNil(t, found)
assert.True(t, found.Sensitive)
assert.Nil(t, found.Value)
})
}