Skip to content

Commit 1d66a39

Browse files
committed
Env
1 parent 537e372 commit 1d66a39

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

provider/examples_test.go

+27-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider_test
22

33
import (
44
"os"
5+
"path/filepath"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -11,28 +12,34 @@ import (
1112
"github.com/coder/terraform-provider-coder/provider"
1213
)
1314

14-
func TestExamples(t *testing.T) {
15+
func TestExamples_CoderParameter(t *testing.T) {
1516
t.Parallel()
1617

17-
for _, testDir := range []string{
18-
"coder_parameter",
19-
"coder_workspace_tags",
20-
} {
21-
t.Run(testDir, func(t *testing.T) {
22-
testDir := testDir
23-
t.Parallel()
24-
25-
resource.Test(t, resource.TestCase{
26-
Providers: map[string]*schema.Provider{
27-
"coder": provider.New(),
28-
},
29-
IsUnitTest: true,
30-
Steps: []resource.TestStep{{
31-
Config: mustReadFile(t, "../examples/resources/"+testDir+"/resource.tf"),
32-
}},
33-
})
34-
})
35-
}
18+
resource.Test(t, resource.TestCase{
19+
Providers: map[string]*schema.Provider{
20+
"coder": provider.New(),
21+
},
22+
IsUnitTest: true,
23+
Steps: []resource.TestStep{{
24+
Config: mustReadFile(t, "../examples/resources/coder_workspace_tags/resource.tf"),
25+
}},
26+
})
27+
}
28+
29+
func TestExamples_CoderWorkspaceTags(t *testing.T) {
30+
// no parallel as the test calls t.Setenv()
31+
workDir := "../examples/resources/coder_workspace_tags"
32+
t.Setenv(provider.TerraformWorkDirEnv, workDir)
33+
34+
resource.Test(t, resource.TestCase{
35+
Providers: map[string]*schema.Provider{
36+
"coder": provider.New(),
37+
},
38+
IsUnitTest: true,
39+
Steps: []resource.TestStep{{
40+
Config: mustReadFile(t, filepath.Join(workDir, "/resource.tf")),
41+
}},
42+
})
3643
}
3744

3845
func mustReadFile(t *testing.T, path string) string {

provider/workspace_tags.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99
)
1010

11+
const TerraformWorkDirEnv = "CODER_TF_WORK_DIR"
12+
1113
type WorkspaceTags struct {
1214
Tag []Tag
1315
}

0 commit comments

Comments
 (0)