(t *testing.T)
| 2660 | } |
| 2661 | |
| 2662 | func TestContainerUsername(t *testing.T) { |
| 2663 | t.Parallel() |
| 2664 | |
| 2665 | client, err := newClient(t, address) |
| 2666 | if err != nil { |
| 2667 | t.Fatal(err) |
| 2668 | } |
| 2669 | defer client.Close() |
| 2670 | |
| 2671 | var ( |
| 2672 | image Image |
| 2673 | ctx, cancel = testContext(t) |
| 2674 | id = t.Name() |
| 2675 | ) |
| 2676 | defer cancel() |
| 2677 | |
| 2678 | image, err = client.GetImage(ctx, testImage) |
| 2679 | if err != nil { |
| 2680 | t.Fatal(err) |
| 2681 | } |
| 2682 | |
| 2683 | username := "www-data" |
| 2684 | command := []string{ |
| 2685 | "id", "-u", |
| 2686 | } |
| 2687 | expectedOutput := "33" |
| 2688 | if runtime.GOOS == "windows" { |
| 2689 | username = "ContainerUser" |
| 2690 | command = []string{ |
| 2691 | "echo", `%USERNAME%`, |
| 2692 | } |
| 2693 | expectedOutput = "ContainerUser" |
| 2694 | } |
| 2695 | |
| 2696 | // the www-data user in the busybox image has a uid of 33 |
| 2697 | container, err := client.NewContainer(ctx, id, |
| 2698 | WithNewSnapshot(id, image), |
| 2699 | WithNewSpec(oci.WithImageConfig(image), oci.WithUsername(username), withProcessArgs(command...)), |
| 2700 | ) |
| 2701 | if err != nil { |
| 2702 | t.Fatal(err) |
| 2703 | } |
| 2704 | defer container.Delete(ctx, WithSnapshotCleanup) |
| 2705 | |
| 2706 | buf := bytes.NewBuffer(nil) |
| 2707 | task, err := container.NewTask(ctx, cio.NewCreator(withStdout(buf))) |
| 2708 | if err != nil { |
| 2709 | t.Fatal(err) |
| 2710 | } |
| 2711 | |
| 2712 | statusC, err := task.Wait(ctx) |
| 2713 | if err != nil { |
| 2714 | t.Fatal(err) |
| 2715 | } |
| 2716 | |
| 2717 | if err := task.Start(ctx); err != nil { |
| 2718 | t.Fatal(err) |
| 2719 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…