MCPcopy Index your code
hub / github.com/coder/coder / TestExecuteOptions

Function TestExecuteOptions

agent/agentscripts/agentscripts_test.go:164–272  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestExecuteOptions(t *testing.T) {
165 t.Parallel()
166
167 startScript := codersdk.WorkspaceAgentScript{
168 ID: uuid.New(),
169 LogSourceID: uuid.New(),
170 Script: "echo start",
171 RunOnStart: true,
172 }
173 stopScript := codersdk.WorkspaceAgentScript{
174 ID: uuid.New(),
175 LogSourceID: uuid.New(),
176 Script: "echo stop",
177 RunOnStop: true,
178 }
179 regularScript := codersdk.WorkspaceAgentScript{
180 ID: uuid.New(),
181 LogSourceID: uuid.New(),
182 Script: "echo regular",
183 }
184
185 scripts := []codersdk.WorkspaceAgentScript{
186 startScript,
187 stopScript,
188 regularScript,
189 }
190
191 scriptByID := func(t *testing.T, id uuid.UUID) codersdk.WorkspaceAgentScript {
192 for _, script := range scripts {
193 if script.ID == id {
194 return script
195 }
196 }
197 t.Fatal("script not found")
198 return codersdk.WorkspaceAgentScript{}
199 }
200
201 wantOutput := map[uuid.UUID]string{
202 startScript.ID: "start",
203 stopScript.ID: "stop",
204 regularScript.ID: "regular",
205 }
206
207 testCases := []struct {
208 name string
209 option agentscripts.ExecuteOption
210 wantRun []uuid.UUID
211 }{
212 {
213 name: "ExecuteAllScripts",
214 option: agentscripts.ExecuteAllScripts,
215 wantRun: []uuid.UUID{startScript.ID, stopScript.ID, regularScript.ID},
216 },
217 {
218 name: "ExecuteStartScripts",
219 option: agentscripts.ExecuteStartScripts,
220 wantRun: []uuid.UUID{startScript.ID},
221 },

Callers

nothing calls this directly

Calls 10

ContextFunction · 0.92
NewFakeAgentAPIFunction · 0.92
LoggerFunction · 0.92
FatalMethod · 0.80
setupFunction · 0.70
NewMethod · 0.65
RunMethod · 0.65
CloseMethod · 0.65
InitMethod · 0.65
ExecuteMethod · 0.65

Tested by

no test coverage detected