MCPcopy Create free account
hub / github.com/coder/envbuilder / TestInitScriptInitCommand

Function TestInitScriptInitCommand

integration/integration_test.go:168–214  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

166}
167
168func TestInitScriptInitCommand(t *testing.T) {
169 t.Parallel()
170
171 ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
172 defer cancel()
173
174 // Init script will hit the below handler to signify INIT_SCRIPT works.
175 initCalled := make(chan struct{})
176 initSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
177 initCalled <- struct{}{}
178 w.WriteHeader(http.StatusOK)
179 }))
180
181 srv := gittest.CreateGitServer(t, gittest.Options{
182 Files: map[string]string{
183 // Let's say /bin/sh is not available and we can only use /bin/ash
184 "Dockerfile": fmt.Sprintf("FROM %s\nRUN unlink /bin/sh", testImageAlpine),
185 },
186 })
187 _, err := runEnvbuilder(t, runOpts{env: []string{
188 envbuilderEnv("GIT_URL", srv.URL),
189 envbuilderEnv("DOCKERFILE_PATH", "Dockerfile"),
190 envbuilderEnv("INIT_SCRIPT", fmt.Sprintf(`wget -O - %q`, initSrv.URL)),
191 envbuilderEnv("INIT_COMMAND", "/bin/ash"),
192 }})
193 require.NoError(t, err)
194
195 select {
196 case <-initCalled:
197 case <-ctx.Done():
198 }
199 require.NoError(t, ctx.Err(), "init script did not execute for prefixed env vars")
200
201 _, err = runEnvbuilder(t, runOpts{env: []string{
202 envbuilderEnv("GIT_URL", srv.URL),
203 envbuilderEnv("DOCKERFILE_PATH", "Dockerfile"),
204 fmt.Sprintf(`INIT_SCRIPT=wget -O - %q`, initSrv.URL),
205 `INIT_COMMAND=/bin/ash`,
206 }})
207 require.NoError(t, err)
208
209 select {
210 case <-initCalled:
211 case <-ctx.Done():
212 }
213 require.NoError(t, ctx.Err(), "init script did not execute for legacy env vars")
214}
215
216func TestDanglingBuildStage(t *testing.T) {
217 t.Parallel()

Callers

nothing calls this directly

Calls 3

CreateGitServerFunction · 0.92
runEnvbuilderFunction · 0.85
envbuilderEnvFunction · 0.85

Tested by

no test coverage detected