3
3
package terraform_test
4
4
5
5
import (
6
- "archive/tar"
7
- "bytes"
8
6
"context"
9
7
"encoding/json"
10
8
"errors"
@@ -28,6 +26,7 @@ import (
28
26
"github.com/coder/coder/v2/provisioner/terraform"
29
27
"github.com/coder/coder/v2/provisionersdk"
30
28
"github.com/coder/coder/v2/provisionersdk/proto"
29
+ "github.com/coder/coder/v2/testutil"
31
30
)
32
31
33
32
type provisionerServeOptions struct {
@@ -78,24 +77,24 @@ func setupProvisioner(t *testing.T, opts *provisionerServeOptions) (context.Cont
78
77
return ctx , api
79
78
}
80
79
81
- func makeTar (t * testing.T , files map [string ]string ) []byte {
82
- t .Helper ()
83
- var buffer bytes.Buffer
84
- writer := tar .NewWriter (& buffer )
85
- for name , content := range files {
86
- err := writer .WriteHeader (& tar.Header {
87
- Name : name ,
88
- Size : int64 (len (content )),
89
- Mode : 0o644 ,
90
- })
91
- require .NoError (t , err )
92
- _ , err = writer .Write ([]byte (content ))
93
- require .NoError (t , err )
94
- }
95
- err := writer .Flush ()
96
- require .NoError (t , err )
97
- return buffer .Bytes ()
98
- }
80
+ // func testutil.CreateTar (t *testing.T, files map[string]string) []byte {
81
+ // t.Helper()
82
+ // var buffer bytes.Buffer
83
+ // writer := tar.NewWriter(&buffer)
84
+ // for name, content := range files {
85
+ // err := writer.WriteHeader(&tar.Header{
86
+ // Name: name,
87
+ // Size: int64(len(content)),
88
+ // Mode: 0o644,
89
+ // })
90
+ // require.NoError(t, err)
91
+ // _, err = writer.Write([]byte(content))
92
+ // require.NoError(t, err)
93
+ // }
94
+ // err := writer.Flush()
95
+ // require.NoError(t, err)
96
+ // return buffer.Bytes()
97
+ // }
99
98
100
99
func configure (ctx context.Context , t * testing.T , client proto.DRPCProvisionerClient , config * proto.Config ) proto.DRPCProvisioner_SessionClient {
101
100
t .Helper ()
@@ -186,7 +185,7 @@ func TestProvision_Cancel(t *testing.T) {
186
185
binaryPath : binPath ,
187
186
})
188
187
sess := configure (ctx , t , api , & proto.Config {
189
- TemplateSourceArchive : makeTar (t , nil ),
188
+ TemplateSourceArchive : testutil . CreateTar (t , nil ),
190
189
})
191
190
192
191
err = sendPlan (sess , proto .WorkspaceTransition_START )
@@ -257,7 +256,7 @@ func TestProvision_CancelTimeout(t *testing.T) {
257
256
})
258
257
259
258
sess := configure (ctx , t , api , & proto.Config {
260
- TemplateSourceArchive : makeTar (t , nil ),
259
+ TemplateSourceArchive : testutil . CreateTar (t , nil ),
261
260
})
262
261
263
262
// provisioner requires plan before apply, so test cancel with plan.
@@ -346,7 +345,7 @@ func TestProvision_TextFileBusy(t *testing.T) {
346
345
})
347
346
348
347
sess := configure (ctx , t , api , & proto.Config {
349
- TemplateSourceArchive : makeTar (t , nil ),
348
+ TemplateSourceArchive : testutil . CreateTar (t , nil ),
350
349
})
351
350
352
351
err = sendPlan (sess , proto .WorkspaceTransition_START )
@@ -758,7 +757,7 @@ func TestProvision(t *testing.T) {
758
757
759
758
ctx , api := setupProvisioner (t , nil )
760
759
sess := configure (ctx , t , api , & proto.Config {
761
- TemplateSourceArchive : makeTar (t , testCase .Files ),
760
+ TemplateSourceArchive : testutil . CreateTar (t , testCase .Files ),
762
761
})
763
762
764
763
planRequest := & proto.Request {Type : & proto.Request_Plan {Plan : & proto.PlanRequest {
@@ -863,7 +862,7 @@ func TestProvision_ExtraEnv(t *testing.T) {
863
862
864
863
ctx , api := setupProvisioner (t , nil )
865
864
sess := configure (ctx , t , api , & proto.Config {
866
- TemplateSourceArchive : makeTar (t , map [string ]string {"main.tf" : `resource "null_resource" "A" {}` }),
865
+ TemplateSourceArchive : testutil . CreateTar (t , map [string ]string {"main.tf" : `resource "null_resource" "A" {}` }),
867
866
})
868
867
869
868
err := sendPlan (sess , proto .WorkspaceTransition_START )
@@ -913,7 +912,7 @@ func TestProvision_SafeEnv(t *testing.T) {
913
912
914
913
ctx , api := setupProvisioner (t , nil )
915
914
sess := configure (ctx , t , api , & proto.Config {
916
- TemplateSourceArchive : makeTar (t , map [string ]string {"main.tf" : echoResource }),
915
+ TemplateSourceArchive : testutil . CreateTar (t , map [string ]string {"main.tf" : echoResource }),
917
916
})
918
917
919
918
err := sendPlan (sess , proto .WorkspaceTransition_START )
0 commit comments