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

Function TestUserFrom

devcontainer/devcontainer_test.go:271–421  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

269}
270
271func TestUserFrom(t *testing.T) {
272 t.Parallel()
273
274 t.Run("Image", func(t *testing.T) {
275 t.Parallel()
276 registry := registrytest.New(t)
277 image, err := partial.UncompressedToImage(emptyImage{configFile: &v1.ConfigFile{
278 Config: v1.Config{
279 User: "example",
280 },
281 }})
282 require.NoError(t, err)
283
284 parsed, err := url.Parse("http://" + registry)
285 require.NoError(t, err)
286 parsed.Path = "coder/test:latest"
287 ref, err := name.ParseReference(strings.TrimPrefix(parsed.String(), "http://"))
288 require.NoError(t, err)
289 err = remote.Write(ref, image)
290 require.NoError(t, err)
291
292 user, err := devcontainer.UserFromImage(ref)
293 require.NoError(t, err)
294 require.Equal(t, "example", user)
295 })
296
297 t.Run("Dockerfile", func(t *testing.T) {
298 t.Parallel()
299 tests := []struct {
300 name string
301 content string
302 user string
303 }{
304 {
305 name: "Empty",
306 content: "FROM scratch",
307 user: "",
308 },
309 {
310 name: "User",
311 content: "FROM scratch\nUSER kyle",
312 user: "kyle",
313 },
314 {
315 name: "Env with default",
316 content: "FROM scratch\nENV MYUSER=maf\nUSER ${MYUSER}",
317 user: "${MYUSER}", // This should be "maf" but the current implementation doesn't support this.
318 },
319 {
320 name: "Env var with default",
321 content: "FROM scratch\nUSER ${MYUSER:-maf}",
322 user: "${MYUSER:-maf}", // This should be "maf" but the current implementation doesn't support this.
323 },
324 {
325 name: "Arg",
326 content: "FROM scratch\nARG MYUSER\nUSER ${MYUSER}",
327 user: "${MYUSER}", // This should be "" or populated but the current implementation doesn't support this.
328 },

Callers

nothing calls this directly

Calls 4

NewFunction · 0.92
UserFromImageFunction · 0.92
UserFromDockerfileFunction · 0.92
WriteMethod · 0.80

Tested by

no test coverage detected