(t *testing.T)
| 1321 | } |
| 1322 | |
| 1323 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…