Skip to content

Commit a81b561

Browse files
committed
found another one
1 parent b09fe9a commit a81b561

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

provisioner/terraform/parse_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/stretchr/testify/require"
1010

1111
"github.com/coder/coder/v2/provisionersdk/proto"
12+
"github.com/coder/coder/v2/testutil"
1213
)
1314

1415
func TestParse(t *testing.T) {
@@ -380,7 +381,7 @@ func TestParse(t *testing.T) {
380381
t.Parallel()
381382

382383
session := configure(ctx, t, api, &proto.Config{
383-
TemplateSourceArchive: makeTar(t, testCase.Files),
384+
TemplateSourceArchive: testutil.CreateTar(t, testCase.Files),
384385
})
385386

386387
err := session.Send(&proto.Request{Type: &proto.Request_Parse{Parse: &proto.ParseRequest{}}})

provisioner/terraform/provision_test.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
package terraform_test
44

55
import (
6-
"archive/tar"
7-
"bytes"
86
"context"
97
"encoding/json"
108
"errors"
@@ -28,6 +26,7 @@ import (
2826
"github.com/coder/coder/v2/provisioner/terraform"
2927
"github.com/coder/coder/v2/provisionersdk"
3028
"github.com/coder/coder/v2/provisionersdk/proto"
29+
"github.com/coder/coder/v2/testutil"
3130
)
3231

3332
type provisionerServeOptions struct {
@@ -78,24 +77,24 @@ func setupProvisioner(t *testing.T, opts *provisionerServeOptions) (context.Cont
7877
return ctx, api
7978
}
8079

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+
// }
9998

10099
func configure(ctx context.Context, t *testing.T, client proto.DRPCProvisionerClient, config *proto.Config) proto.DRPCProvisioner_SessionClient {
101100
t.Helper()
@@ -186,7 +185,7 @@ func TestProvision_Cancel(t *testing.T) {
186185
binaryPath: binPath,
187186
})
188187
sess := configure(ctx, t, api, &proto.Config{
189-
TemplateSourceArchive: makeTar(t, nil),
188+
TemplateSourceArchive: testutil.CreateTar(t, nil),
190189
})
191190

192191
err = sendPlan(sess, proto.WorkspaceTransition_START)
@@ -257,7 +256,7 @@ func TestProvision_CancelTimeout(t *testing.T) {
257256
})
258257

259258
sess := configure(ctx, t, api, &proto.Config{
260-
TemplateSourceArchive: makeTar(t, nil),
259+
TemplateSourceArchive: testutil.CreateTar(t, nil),
261260
})
262261

263262
// provisioner requires plan before apply, so test cancel with plan.
@@ -346,7 +345,7 @@ func TestProvision_TextFileBusy(t *testing.T) {
346345
})
347346

348347
sess := configure(ctx, t, api, &proto.Config{
349-
TemplateSourceArchive: makeTar(t, nil),
348+
TemplateSourceArchive: testutil.CreateTar(t, nil),
350349
})
351350

352351
err = sendPlan(sess, proto.WorkspaceTransition_START)
@@ -758,7 +757,7 @@ func TestProvision(t *testing.T) {
758757

759758
ctx, api := setupProvisioner(t, nil)
760759
sess := configure(ctx, t, api, &proto.Config{
761-
TemplateSourceArchive: makeTar(t, testCase.Files),
760+
TemplateSourceArchive: testutil.CreateTar(t, testCase.Files),
762761
})
763762

764763
planRequest := &proto.Request{Type: &proto.Request_Plan{Plan: &proto.PlanRequest{
@@ -863,7 +862,7 @@ func TestProvision_ExtraEnv(t *testing.T) {
863862

864863
ctx, api := setupProvisioner(t, nil)
865864
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" {}`}),
867866
})
868867

869868
err := sendPlan(sess, proto.WorkspaceTransition_START)
@@ -913,7 +912,7 @@ func TestProvision_SafeEnv(t *testing.T) {
913912

914913
ctx, api := setupProvisioner(t, nil)
915914
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}),
917916
})
918917

919918
err := sendPlan(sess, proto.WorkspaceTransition_START)

provisioner/terraform/timings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestTimingsFromProvision(t *testing.T) {
3434
binaryPath: fakeBin,
3535
})
3636
sess := configure(ctx, t, api, &proto.Config{
37-
TemplateSourceArchive: makeTar(t, nil),
37+
TemplateSourceArchive: testutil.CreateTar(t, nil),
3838
})
3939

4040
ctx, cancel := context.WithTimeout(ctx, testutil.WaitLong)

0 commit comments

Comments
 (0)