@@ -4,6 +4,8 @@ package terraform_test
44
55import (
66 "encoding/json"
7+ "os"
8+ "path/filepath"
79 "testing"
810
911 "github.com/stretchr/testify/require"
@@ -15,14 +17,18 @@ import (
1517func TestParse (t * testing.T ) {
1618 t .Parallel ()
1719
18- ctx , api := setupProvisioner (t , nil )
20+ cwd , err := os .Getwd ()
21+ require .NoError (t , err )
22+
23+ ctx , api := setupProvisioner (t , & provisionerServeOptions {
24+ // Fake all actual terraform, since parse doesn't need it.
25+ binaryPath : filepath .Join (cwd , "testdata" , "timings-aggregation" , "fake-terraform.sh" ),
26+ })
1927
2028 testCases := []struct {
21- Name string
22- Files map [string ]string
23- Response * proto.ParseComplete
24- // If ErrorContains is not empty, then the InitComplete should have an Error containing the given string
25- ErrorContains string
29+ Name string
30+ Files map [string ]string
31+ Response * proto.ParseComplete
2632 ParseErrorContains string
2733 }{
2834 {
@@ -82,7 +88,7 @@ func TestParse(t *testing.T) {
8288 Files : map [string ]string {
8389 "main.tf" : "a;sd;ajsd;lajsd;lasjdf;a" ,
8490 },
85- ErrorContains : `initialize terraform: exit status 1 ` ,
91+ ParseErrorContains : `The ";" character is not valid. ` ,
8692 },
8793 {
8894 Name : "multiple-variables" ,
@@ -208,13 +214,6 @@ func TestParse(t *testing.T) {
208214 Name : "workspace-tags" ,
209215 Files : map [string ]string {
210216 `main.tf` : `
211- terraform {
212- required_providers {
213- coder = {
214- source = "coder/coder"
215- }
216- }
217- }
218217 ` ,
219218 "parameters.tf" : `data "coder_parameter" "os_selector" {
220219 name = "os_selector"
@@ -277,13 +276,6 @@ func TestParse(t *testing.T) {
277276 Name : "workspace-tags-in-a-single-file" ,
278277 Files : map [string ]string {
279278 "main.tf" : `
280- terraform {
281- required_providers {
282- coder = {
283- source = "coder/coder"
284- }
285- }
286- }
287279 data "coder_parameter" "os_selector" {
288280 name = "os_selector"
289281 display_name = "Operating System"
@@ -347,13 +339,6 @@ func TestParse(t *testing.T) {
347339 Name : "workspace-tags-duplicate-tag" ,
348340 Files : map [string ]string {
349341 "main.tf" : `
350- terraform {
351- required_providers {
352- coder = {
353- source = "coder/coder"
354- }
355- }
356- }
357342 data "coder_workspace_tags" "custom_workspace_tags" {
358343 tags = {
359344 "cluster" = "developers"
@@ -370,14 +355,6 @@ func TestParse(t *testing.T) {
370355 Name : "workspace-tags-wrong-tag-format" ,
371356 Files : map [string ]string {
372357 "main.tf" : `
373- terraform {
374- required_providers {
375- coder = {
376- source = "coder/coder"
377- }
378- }
379- }
380-
381358 data "coder_workspace_tags" "custom_workspace_tags" {
382359 tags {
383360 cluster = "developers"
@@ -413,19 +390,14 @@ func TestParse(t *testing.T) {
413390 err := sendInit (session , testutil .CreateTar (t , testCase .Files ))
414391 require .NoError (t , err )
415392
416- // Init stage
393+ // Init stage -- a fake terraform, will always succeed quickly.
417394 for {
418395 msg , err := session .Recv ()
419396 require .NoError (t , err )
420397 if msgLog , ok := msg .Type .(* proto.Response_Log ); ok {
421398 t .Logf ("init log: %s" , msgLog .Log .Output )
422399 continue
423400 }
424-
425- if testCase .ErrorContains != "" {
426- require .Contains (t , msg .GetInit ().GetError (), testCase .ErrorContains )
427- return // Stop test at this point
428- }
429401 break
430402 }
431403
0 commit comments