fix: Ensure terraform tests have a cache path and logger (#3161)

* fix: Ensure terraform tests have a cache path and logger

* fix: Protect against concurrent `terraform init`
This commit is contained in:
Mathias Fredriksson
2022-08-04 20:37:07 +03:00
committed by GitHub
parent ad20b23178
commit fb9fca8bc9
4 changed files with 33 additions and 28 deletions

View File

@ -3,40 +3,20 @@
package terraform_test
import (
"context"
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coder/coder/provisioner/terraform"
"github.com/coder/coder/provisionersdk"
"github.com/coder/coder/provisionersdk/proto"
)
func TestParse(t *testing.T) {
t.Parallel()
// Create an in-memory provisioner to communicate with.
client, server := provisionersdk.TransportPipe()
ctx, cancelFunc := context.WithCancel(context.Background())
t.Cleanup(func() {
_ = client.Close()
_ = server.Close()
cancelFunc()
})
go func() {
err := terraform.Serve(ctx, &terraform.ServeOptions{
ServeOptions: &provisionersdk.ServeOptions{
Listener: server,
},
})
assert.NoError(t, err)
}()
api := proto.NewDRPCProvisionerClient(provisionersdk.Conn(client))
ctx, api := setupProvisioner(t)
testCases := []struct {
Name string
@ -175,7 +155,8 @@ func TestParse(t *testing.T) {
DefaultDestination: &proto.ParameterDestination{
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
},
}},
},
},
},
},
},