Skip to content

Commit ed534d7

Browse files
committed
Tests
Signed-off-by: Danny Kopping <[email protected]>
1 parent b29499b commit ed534d7

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

provider/app_test.go

+59
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,63 @@ func TestApp(t *testing.T) {
309309
}
310310
})
311311

312+
t.Run("CORS Behavior", func(t *testing.T) {
313+
t.Parallel()
314+
315+
baseConfig := `
316+
provider "coder" {}
317+
resource "coder_agent" "dev" {
318+
os = "linux"
319+
arch = "amd64"
320+
}
321+
resource "coder_app" "test" {
322+
agent_id = coder_agent.dev.id
323+
slug = "test"
324+
display_name = "Testing"
325+
url = "https://google.com"
326+
external = true
327+
%s
328+
}`
329+
330+
cases := []struct {
331+
name string
332+
config string
333+
behavior string
334+
}{{
335+
name: "Default CORS",
336+
config: fmt.Sprintf(baseConfig, ""),
337+
behavior: "simple",
338+
}, {
339+
name: "Simple CORS",
340+
config: fmt.Sprintf(baseConfig, "cors_behavior = \"simple\""),
341+
behavior: "simple",
342+
}, {
343+
name: "Passthru CORS",
344+
config: fmt.Sprintf(baseConfig, "cors_behavior = \"passthru\""),
345+
behavior: "passthru",
346+
}}
347+
for _, tc := range cases {
348+
tc := tc
349+
t.Run(tc.name, func(t *testing.T) {
350+
t.Parallel()
351+
resource.Test(t, resource.TestCase{
352+
ProviderFactories: coderFactory(),
353+
IsUnitTest: true,
354+
Steps: []resource.TestStep{{
355+
Config: tc.config,
356+
Check: func(state *terraform.State) error {
357+
require.Len(t, state.Modules, 1)
358+
require.Len(t, state.Modules[0].Resources, 2)
359+
resource := state.Modules[0].Resources["coder_app.test"]
360+
require.NotNil(t, resource)
361+
require.Equal(t, tc.behavior, resource.Primary.Attributes["cors_behavior"])
362+
return nil
363+
},
364+
ExpectError: nil,
365+
}},
366+
})
367+
})
368+
}
369+
})
370+
312371
}

0 commit comments

Comments
 (0)