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

Function serveScript

provisionersdk/agent_test.go:135–154  ·  view source on GitHub ↗

serveScript creates a fake HTTP server which serves a requested "agent binary" (which is actually the given input string) which will be attempted to run to verify that it is correct.

(t *testing.T, in string)

Source from the content-addressed store, hash-verified

133// serveScript creates a fake HTTP server which serves a requested "agent binary" (which is actually the given input string)
134// which will be attempted to run to verify that it is correct.
135func serveScript(t *testing.T, in string) string {
136 t.Helper()
137
138 srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
139 rw.WriteHeader(http.StatusOK)
140 _, _ = rw.Write([]byte(in))
141 }))
142 t.Cleanup(srv.Close)
143 srvURL, err := url.Parse(srv.URL)
144 require.NoError(t, err)
145
146 script, exists := provisionersdk.AgentScriptEnv()[fmt.Sprintf("CODER_AGENT_SCRIPT_%s_%s", runtime.GOOS, runtime.GOARCH)]
147 if !exists {
148 t.Skip("Agent not supported...")
149 return ""
150 }
151 script = strings.ReplaceAll(script, "${ACCESS_URL}", srvURL.String()+"/")
152 script = strings.ReplaceAll(script, "${AUTH_TYPE}", "token")
153 return script
154}

Callers 1

TestAgentScriptFunction · 0.85

Calls 8

AgentScriptEnvFunction · 0.92
SkipMethod · 0.80
HelperMethod · 0.65
WriteMethod · 0.65
CleanupMethod · 0.65
ParseMethod · 0.65
WriteHeaderMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected