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)
| 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. |
| 135 | func 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 | } |
no test coverage detected