@@ -26,101 +26,102 @@ import (
26
26
"github.com/coder/coder/v2/testutil"
27
27
)
28
28
29
- // TestDevcontainerCLIUp tests the Up method of the DevcontainerCLI implementation.
30
- //
31
29
//nolint:paralleltest // This test is not parallel-safe due to t.Setenv.
32
- func TestDevcontainerCLI_Up_ArgsAndParsing (t * testing.T ) {
30
+ func TestDevcontainerCLI_ArgsAndParsing (t * testing.T ) {
33
31
testExePath , err := os .Executable ()
34
32
require .NoError (t , err , "get test executable path" )
35
33
36
34
logger := slogtest .Make (t , & slogtest.Options {IgnoreErrors : true }).Leveled (slog .LevelDebug )
37
35
testExecer := & testDevcontainerExecer {testExePath : testExePath }
38
36
39
- tests := []struct {
40
- name string
41
- logFile string
42
- workspace string
43
- config string
44
- opts []agentcontainers.DevcontainerCLIUpOptions
45
- wantArgs string
46
- wantError bool
47
- }{
48
- {
49
- name : "success" ,
50
- logFile : "up.log" ,
51
- workspace : "/test/workspace" ,
52
- wantArgs : "up --log-format json --workspace-folder /test/workspace" ,
53
- wantError : false ,
54
- },
55
- {
56
- name : "success with config" ,
57
- logFile : "up.log" ,
58
- workspace : "/test/workspace" ,
59
- config : "/test/config.json" ,
60
- wantArgs : "up --log-format json --workspace-folder /test/workspace --config /test/config.json" ,
61
- wantError : false ,
62
- },
63
- {
64
- name : "already exists" ,
65
- logFile : "up-already-exists.log" ,
66
- workspace : "/test/workspace" ,
67
- wantArgs : "up --log-format json --workspace-folder /test/workspace" ,
68
- wantError : false ,
69
- },
70
- {
71
- name : "docker error" ,
72
- logFile : "up-error-docker.log" ,
73
- workspace : "/test/workspace" ,
74
- wantArgs : "up --log-format json --workspace-folder /test/workspace" ,
75
- wantError : true ,
76
- },
77
- {
78
- name : "bad outcome" ,
79
- logFile : "up-error-bad-outcome.log" ,
80
- workspace : "/test/workspace" ,
81
- wantArgs : "up --log-format json --workspace-folder /test/workspace" ,
82
- wantError : true ,
83
- },
84
- {
85
- name : "does not exist" ,
86
- logFile : "up-error-does-not-exist.log" ,
87
- workspace : "/test/workspace" ,
88
- wantArgs : "up --log-format json --workspace-folder /test/workspace" ,
89
- wantError : true ,
90
- },
91
- {
92
- name : "with remove existing container" ,
93
- logFile : "up.log" ,
94
- workspace : "/test/workspace" ,
95
- opts : []agentcontainers.DevcontainerCLIUpOptions {
96
- agentcontainers .WithRemoveExistingContainer (),
37
+ //nolint:paralleltest // This test is not parallel-safe due to t.Setenv.
38
+ t .Run ("Up" , func (t * testing.T ) {
39
+ tests := []struct {
40
+ name string
41
+ logFile string
42
+ workspace string
43
+ config string
44
+ opts []agentcontainers.DevcontainerCLIUpOptions
45
+ wantArgs string
46
+ wantError bool
47
+ }{
48
+ {
49
+ name : "success" ,
50
+ logFile : "up.log" ,
51
+ workspace : "/test/workspace" ,
52
+ wantArgs : "up --log-format json --workspace-folder /test/workspace" ,
53
+ wantError : false ,
97
54
},
98
- wantArgs : "up --log-format json --workspace-folder /test/workspace --remove-existing-container" ,
99
- wantError : false ,
100
- },
101
- }
55
+ {
56
+ name : "success with config" ,
57
+ logFile : "up.log" ,
58
+ workspace : "/test/workspace" ,
59
+ config : "/test/config.json" ,
60
+ wantArgs : "up --log-format json --workspace-folder /test/workspace --config /test/config.json" ,
61
+ wantError : false ,
62
+ },
63
+ {
64
+ name : "already exists" ,
65
+ logFile : "up-already-exists.log" ,
66
+ workspace : "/test/workspace" ,
67
+ wantArgs : "up --log-format json --workspace-folder /test/workspace" ,
68
+ wantError : false ,
69
+ },
70
+ {
71
+ name : "docker error" ,
72
+ logFile : "up-error-docker.log" ,
73
+ workspace : "/test/workspace" ,
74
+ wantArgs : "up --log-format json --workspace-folder /test/workspace" ,
75
+ wantError : true ,
76
+ },
77
+ {
78
+ name : "bad outcome" ,
79
+ logFile : "up-error-bad-outcome.log" ,
80
+ workspace : "/test/workspace" ,
81
+ wantArgs : "up --log-format json --workspace-folder /test/workspace" ,
82
+ wantError : true ,
83
+ },
84
+ {
85
+ name : "does not exist" ,
86
+ logFile : "up-error-does-not-exist.log" ,
87
+ workspace : "/test/workspace" ,
88
+ wantArgs : "up --log-format json --workspace-folder /test/workspace" ,
89
+ wantError : true ,
90
+ },
91
+ {
92
+ name : "with remove existing container" ,
93
+ logFile : "up.log" ,
94
+ workspace : "/test/workspace" ,
95
+ opts : []agentcontainers.DevcontainerCLIUpOptions {
96
+ agentcontainers .WithRemoveExistingContainer (),
97
+ },
98
+ wantArgs : "up --log-format json --workspace-folder /test/workspace --remove-existing-container" ,
99
+ wantError : false ,
100
+ },
101
+ }
102
102
103
- for _ , tt := range tests {
104
- //nolint:paralleltest // This test is not parallel-safe due t.Setenv.
105
- t .Run (tt .name , func (t * testing.T ) {
106
- ctx := testutil .Context (t , testutil .WaitShort )
107
-
108
- // Set environment variables for the test helper.
109
- t .Setenv ("TEST_DEVCONTAINER_WANT_ARGS" , tt .wantArgs )
110
- t .Setenv ("TEST_DEVCONTAINER_WANT_ERROR" , fmt .Sprintf ("%v" , tt .wantError ))
111
- t .Setenv ("TEST_DEVCONTAINER_LOG_FILE" , filepath .Join ("testdata" , "devcontainercli" , "parse" , tt .logFile ))
112
-
113
- dccli := agentcontainers .NewDevcontainerCLI (logger , testExecer )
114
- containerID , err := dccli .Up (ctx , tt .workspace , tt .config , tt .opts ... )
115
- if tt .wantError {
116
- assert .Error (t , err , "want error" )
117
- assert .Empty (t , containerID , "expected empty container ID" )
118
- } else {
119
- assert .NoError (t , err , "want no error" )
120
- assert .NotEmpty (t , containerID , "expected non-empty container ID" )
121
- }
122
- })
123
- }
103
+ for _ , tt := range tests {
104
+ //nolint:paralleltest // This test is not parallel-safe due t.Setenv.
105
+ t .Run (tt .name , func (t * testing.T ) {
106
+ ctx := testutil .Context (t , testutil .WaitShort )
107
+
108
+ // Set environment variables for the test helper.
109
+ t .Setenv ("TEST_DEVCONTAINER_WANT_ARGS" , tt .wantArgs )
110
+ t .Setenv ("TEST_DEVCONTAINER_WANT_ERROR" , fmt .Sprintf ("%v" , tt .wantError ))
111
+ t .Setenv ("TEST_DEVCONTAINER_LOG_FILE" , filepath .Join ("testdata" , "devcontainercli" , "parse" , tt .logFile ))
112
+
113
+ dccli := agentcontainers .NewDevcontainerCLI (logger , testExecer )
114
+ containerID , err := dccli .Up (ctx , tt .workspace , tt .config , tt .opts ... )
115
+ if tt .wantError {
116
+ assert .Error (t , err , "want error" )
117
+ assert .Empty (t , containerID , "expected empty container ID" )
118
+ } else {
119
+ assert .NoError (t , err , "want no error" )
120
+ assert .NotEmpty (t , containerID , "expected non-empty container ID" )
121
+ }
122
+ })
123
+ }
124
+ })
124
125
}
125
126
126
127
// testDevcontainerExecer implements the agentexec.Execer interface for testing.
0 commit comments