Skip to content

Commit 9a6ab44

Browse files
committed
more tests
1 parent b93321e commit 9a6ab44

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

provisioner/terraform/provision_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"path/filepath"
1414
"sort"
1515
"strings"
16+
"sync"
1617
"testing"
1718
"time"
1819

@@ -180,7 +181,7 @@ func TestProvision_Cancel(t *testing.T) {
180181
// Provisioner requires a plan before an apply, so test cancel with plan.
181182
name: "Cancel plan",
182183
mode: "plan",
183-
startSequence: []string{"init", "plan_start"},
184+
startSequence: []string{"init_start", "plan_start"},
184185
wantLog: []string{"interrupt", "exit"},
185186
},
186187
}
@@ -202,25 +203,37 @@ func TestProvision_Cancel(t *testing.T) {
202203
binaryPath: binPath,
203204
})
204205
sess := configure(ctx, t, api, &proto.Config{})
205-
_ = initDo(t, sess, testutil.CreateTar(t, nil))
206206

207-
err = sendPlan(sess, proto.WorkspaceTransition_START)
207+
err = sendInit(sess, testutil.CreateTar(t, nil))
208208
require.NoError(t, err)
209209

210+
var planOnce sync.Once
211+
210212
for _, line := range tt.startSequence {
211213
LoopStart:
212214
msg, err := sess.Recv()
213215
require.NoError(t, err)
214216

215217
t.Log(msg.Type)
218+
if msg.GetInit() != nil && msg.GetInit().GetError() == "" {
219+
planOnce.Do(func() {
220+
t.Log("Sending terraform plan request")
221+
// Send plan after init
222+
err = sendPlan(sess, proto.WorkspaceTransition_START)
223+
require.NoError(t, err)
224+
})
225+
continue
226+
}
216227

217228
log := msg.GetLog()
218229
if log == nil {
219230
goto LoopStart
220231
}
232+
221233
require.Equal(t, line, log.Output)
222234
}
223235

236+
t.Log("Sending the cancel request")
224237
err = sess.Send(&proto.Request{
225238
Type: &proto.Request_Cancel{
226239
Cancel: &proto.CancelRequest{},

0 commit comments

Comments
 (0)