(t *testing.T)
| 269 | } |
| 270 | |
| 271 | func 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 | }, |
nothing calls this directly
no test coverage detected