ns.go 590 B

123456789101112131415161718192021
  1. package container
  2. import (
  3. "context"
  4. "strings"
  5. "testing"
  6. "github.com/docker/docker/client"
  7. "gotest.tools/v3/assert"
  8. is "gotest.tools/v3/assert/cmp"
  9. )
  10. // GetContainerNS gets the value of the specified namespace of a container
  11. func GetContainerNS(ctx context.Context, t *testing.T, apiClient client.APIClient, cID, nsName string) string {
  12. t.Helper()
  13. res, err := Exec(ctx, apiClient, cID, []string{"readlink", "/proc/self/ns/" + nsName})
  14. assert.NilError(t, err)
  15. assert.Assert(t, is.Len(res.Stderr(), 0))
  16. assert.Equal(t, 0, res.ExitCode)
  17. return strings.TrimSpace(res.Stdout())
  18. }