Skip to content

Commit 2500b9c

Browse files
committed
bad tests but passing :^)
1 parent 9fc4cb8 commit 2500b9c

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed

internal/provider/license_resource_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestAccLicenseResource(t *testing.T) {
2424
t.Skip("No license found for license resource tests, skipping")
2525
}
2626

27-
cfg1 := testAccLicenseResourceconfig{
27+
cfg1 := testAccLicenseResourceConfig{
2828
URL: client.URL.String(),
2929
Token: client.SessionToken(),
3030
License: license,
@@ -42,13 +42,13 @@ func TestAccLicenseResource(t *testing.T) {
4242
})
4343
}
4444

45-
type testAccLicenseResourceconfig struct {
45+
type testAccLicenseResourceConfig struct {
4646
URL string
4747
Token string
4848
License string
4949
}
5050

51-
func (c testAccLicenseResourceconfig) String(t *testing.T) string {
51+
func (c testAccLicenseResourceConfig) String(t *testing.T) string {
5252
t.Helper()
5353
tpl := `
5454
provider coderd {

internal/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func (p *CoderdProvider) Resources(ctx context.Context) []func() resource.Resour
139139
NewWorkspaceProxyResource,
140140
NewLicenseResource,
141141
NewOrganizationResource,
142+
NewProvisionerKeyResource,
142143
}
143144
}
144145

internal/provider/provisioner_key_resource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,21 @@ func (r *ProvisionerKeyResource) Schema(ctx context.Context, req resource.Schema
4747
"organization_id": schema.StringAttribute{
4848
CustomType: UUIDType,
4949
MarkdownDescription: "The organization that provisioners connected with this key will be connected to.",
50+
Required: true,
5051
PlanModifiers: []planmodifier.String{
5152
stringplanmodifier.RequiresReplace(),
5253
},
5354
},
5455
"name": schema.StringAttribute{
5556
MarkdownDescription: "The name of the key.",
57+
Required: true,
5658
PlanModifiers: []planmodifier.String{
5759
stringplanmodifier.RequiresReplace(),
5860
},
5961
},
6062
"tags": schema.MapAttribute{
6163
ElementType: types.StringType,
64+
Optional: true,
6265
MarkdownDescription: "The tags that the provisioner will accept jobs for.",
6366
PlanModifiers: []planmodifier.Map{
6467
mapplanmodifier.RequiresReplace(),

internal/provider/provisioner_key_resource_test.go

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,38 @@ import (
88
"text/template"
99

1010
"github.com/coder/terraform-provider-coderd/integration"
11+
"github.com/google/uuid"
1112
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1213
"github.com/stretchr/testify/require"
1314
)
1415

15-
func TestAccLicenseResource(t *testing.T) {
16+
func TestAccProvisionerKeyResource(t *testing.T) {
1617
if os.Getenv("TF_ACC") == "" {
1718
t.Skip("Acceptance tests are disabled.")
1819
}
1920
ctx := context.Background()
20-
client := integration.StartCoder(ctx, t, "license_acc", false)
21+
client := integration.StartCoder(ctx, t, "license_acc", true)
22+
orgs, err := client.Organizations(ctx)
23+
require.NoError(t, err)
24+
firstOrg := orgs[0].ID
2125

2226
license := os.Getenv("CODER_ENTERPRISE_LICENSE")
2327
if license == "" {
2428
t.Skip("No license found for license resource tests, skipping")
2529
}
2630

27-
cfg1 := testAccLicenseResourceconfig{
28-
URL: client.URL.String(),
29-
Token: client.SessionToken(),
30-
License: license,
31+
cfg1 := testAccProvisionerKeyResourceConfig{
32+
URL: client.URL.String(),
33+
Token: client.SessionToken(),
34+
35+
OrganizationID: firstOrg,
36+
Name: "example-provisioner-key",
37+
}
38+
39+
cfg2 := cfg1
40+
cfg2.Name = "different-provisioner-key"
41+
cfg2.Tags = map[string]string{
42+
"wibble": "wobble",
3143
}
3244

3345
resource.Test(t, resource.TestCase{
@@ -38,34 +50,44 @@ func TestAccLicenseResource(t *testing.T) {
3850
{
3951
Config: cfg1.String(t),
4052
},
53+
{
54+
Config: cfg2.String(t),
55+
},
4156
},
4257
})
4358
}
4459

45-
type testAccLicenseResourceconfig struct {
46-
URL string
47-
Token string
48-
License string
60+
type testAccProvisionerKeyResourceConfig struct {
61+
URL string
62+
Token string
63+
64+
OrganizationID uuid.UUID
65+
Name string
66+
Tags map[string]string
4967
}
5068

51-
func (c testAccLicenseResourceconfig) String(t *testing.T) string {
69+
func (c testAccProvisionerKeyResourceConfig) String(t *testing.T) string {
5270
t.Helper()
5371
tpl := `
5472
provider coderd {
5573
url = "{{.URL}}"
5674
token = "{{.Token}}"
5775
}
5876
59-
resource "coderd_license" "test" {
60-
license = "{{.License}}"
77+
resource "coderd_provisioner_key" "test" {
78+
organization_id = "{{.OrganizationID}}"
79+
name = "{{.Name}}"
80+
81+
tags = {
82+
{{- range $key, $value := .Tags}}
83+
{{$key}} = "{{$value}}"
84+
{{- end}}
85+
}
6186
}
6287
`
63-
funcMap := template.FuncMap{
64-
"orNull": PrintOrNull,
65-
}
6688

6789
buf := strings.Builder{}
68-
tmpl, err := template.New("licenseResource").Funcs(funcMap).Parse(tpl)
90+
tmpl, err := template.New("provisionerKeyResource").Parse(tpl)
6991
require.NoError(t, err)
7092

7193
err = tmpl.Execute(&buf, c)

0 commit comments

Comments
 (0)