1
+ # Test for coder-login module
2
+
3
+ run "test_coder_login_module" {
4
+ command = plan
5
+
6
+ variables {
7
+ agent_id = " test-agent-id"
8
+ }
9
+
10
+ # Test that the coder_env resources are created with correct configuration
11
+ assert {
12
+ condition = coder_env. coder_session_token . agent_id == " test-agent-id"
13
+ error_message = " CODER_SESSION_TOKEN agent ID should match the input variable"
14
+ }
15
+
16
+ assert {
17
+ condition = coder_env. coder_session_token . name == " CODER_SESSION_TOKEN"
18
+ error_message = " Environment variable name should be 'CODER_SESSION_TOKEN'"
19
+ }
20
+
21
+ assert {
22
+ condition = coder_env. coder_url . agent_id == " test-agent-id"
23
+ error_message = " CODER_URL agent ID should match the input variable"
24
+ }
25
+
26
+ assert {
27
+ condition = coder_env. coder_url . name == " CODER_URL"
28
+ error_message = " Environment variable name should be 'CODER_URL'"
29
+ }
30
+ }
31
+
32
+ # Test with mock data sources
33
+ run "test_with_mock_data" {
34
+ command = plan
35
+
36
+ variables {
37
+ agent_id = " mock-agent"
38
+ }
39
+
40
+ # Mock the data sources for testing
41
+ override_data {
42
+ target = data. coder_workspace . me
43
+ values = {
44
+ access_url = " https://coder.example.com"
45
+ }
46
+ }
47
+
48
+ override_data {
49
+ target = data. coder_workspace_owner . me
50
+ values = {
51
+ session_token = " mock-session-token"
52
+ }
53
+ }
54
+
55
+ # Verify environment variables get the mocked values
56
+ assert {
57
+ condition = coder_env. coder_url . value == " https://coder.example.com"
58
+ error_message = " CODER_URL should match workspace access_url"
59
+ }
60
+
61
+ assert {
62
+ condition = coder_env. coder_session_token . value == " mock-session-token"
63
+ error_message = " CODER_SESSION_TOKEN should match workspace owner session_token"
64
+ }
65
+ }
0 commit comments