forked from hashicorp/go-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan_test.go
72 lines (57 loc) · 1.72 KB
/
plan_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
package tfe
import (
"context"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPlansRead(t *testing.T) {
client := testClient(t)
ctx := context.Background()
rTest, rTestCleanup := createPlannedRun(t, client, nil)
defer rTestCleanup()
t.Run("when the plan exists", func(t *testing.T) {
p, err := client.Plans.Read(ctx, rTest.Plan.ID)
assert.NoError(t, err)
assert.True(t, p.HasChanges)
assert.NotEmpty(t, p.LogReadURL)
assert.Equal(t, p.Status, PlanFinished)
assert.NotEmpty(t, p.StatusTimestamps)
})
t.Run("when the plan does not exist", func(t *testing.T) {
p, err := client.Plans.Read(ctx, "nonexisting")
assert.Nil(t, p)
assert.Equal(t, err, ErrResourceNotFound)
})
t.Run("with invalid plan ID", func(t *testing.T) {
p, err := client.Plans.Read(ctx, badIdentifier)
assert.Nil(t, p)
assert.EqualError(t, err, "Invalid value for plan ID")
})
}
func TestPlansLogs(t *testing.T) {
client := testClient(t)
ctx := context.Background()
rTest, rTestCleanup := createPlannedRun(t, client, nil)
defer rTestCleanup()
t.Run("when the log exists", func(t *testing.T) {
p, err := client.Plans.Read(ctx, rTest.Plan.ID)
require.NoError(t, err)
logReader, err := client.Plans.Logs(ctx, p.ID)
require.NoError(t, err)
logs, err := ioutil.ReadAll(logReader)
require.NoError(t, err)
assert.Contains(t, string(logs), "1 to add, 0 to change, 0 to destroy")
})
t.Run("when the log does not exist", func(t *testing.T) {
p, err := client.Plans.Read(ctx, rTest.Plan.ID)
require.NoError(t, err)
logs, err := client.Plans.Logs(
ctx,
p.LogReadURL[:len(p.LogReadURL)-10]+"nonexisting",
)
assert.Nil(t, logs)
assert.Error(t, err)
})
}