MCPcopy
hub / github.com/containerd/containerd / TestContainerUsername

Function TestContainerUsername

integration/client/container_test.go:2662–2729  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2660}
2661
2662func 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 }

Callers

nothing calls this directly

Calls 15

DeleteMethod · 0.95
NewTaskMethod · 0.95
WithImageConfigFunction · 0.92
WithUsernameFunction · 0.92
NewCreatorFunction · 0.92
newClientFunction · 0.85
testContextFunction · 0.85
WithNewSpecFunction · 0.85
withStdoutFunction · 0.85
FatalMethod · 0.80
withProcessArgsFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…