MCPcopy
hub / github.com/containerd/containerd / TestContainerHostname

Function TestContainerHostname

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

Source from the content-addressed store, hash-verified

1321}
1322
1323func TestContainerHostname(t *testing.T) {
1324 t.Parallel()
1325
1326 client, err := newClient(t, address)
1327 if err != nil {
1328 t.Fatal(err)
1329 }
1330 defer client.Close()
1331
1332 var (
1333 image Image
1334 ctx, cancel = testContext(t)
1335 id = t.Name()
1336 expected = "myhostname"
1337 )
1338 defer cancel()
1339
1340 image, err = client.GetImage(ctx, testImage)
1341 if err != nil {
1342 t.Fatal(err)
1343 }
1344
1345 container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image),
1346 withProcessArgs("hostname"),
1347 oci.WithHostname(expected),
1348 ))
1349 if err != nil {
1350 t.Fatal(err)
1351 }
1352 defer container.Delete(ctx, WithSnapshotCleanup)
1353
1354 stdout := bytes.NewBuffer(nil)
1355 task, err := container.NewTask(ctx, cio.NewCreator(withStdout(stdout)))
1356 if err != nil {
1357 t.Fatal(err)
1358 }
1359 defer task.Delete(ctx)
1360
1361 statusC, err := task.Wait(ctx)
1362 if err != nil {
1363 t.Fatal(err)
1364 }
1365
1366 if err := task.Start(ctx); err != nil {
1367 t.Fatal(err)
1368 }
1369
1370 status := <-statusC
1371 code, _, err := status.Result()
1372 if err != nil {
1373 t.Fatal(err)
1374 }
1375 if code != 0 {
1376 t.Errorf("expected status 0 but received %d", code)
1377 }
1378 if _, err := task.Delete(ctx); err != nil {
1379 t.Fatal(err)
1380 }

Callers

nothing calls this directly

Calls 15

DeleteMethod · 0.95
NewTaskMethod · 0.95
WithImageConfigFunction · 0.92
WithHostnameFunction · 0.92
NewCreatorFunction · 0.92
newClientFunction · 0.85
testContextFunction · 0.85
WithNewSpecFunction · 0.85
withStdoutFunction · 0.85
FatalMethod · 0.80
ResultMethod · 0.80
withProcessArgsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…