summaryrefslogtreecommitdiff
path: root/integration/internal/container/ns.go
blob: bda06dd74c6f047eeccc45ebb4a6b4a119f4ac71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package container

import (
	"context"
	"strings"
	"testing"

	"github.com/docker/docker/client"
	"gotest.tools/v3/assert"
	is "gotest.tools/v3/assert/cmp"
)

// GetContainerNS gets the value of the specified namespace of a container
func GetContainerNS(ctx context.Context, t *testing.T, client client.APIClient, cID, nsName string) string {
	t.Helper()
	res, err := Exec(ctx, client, cID, []string{"readlink", "/proc/self/ns/" + nsName})
	assert.NilError(t, err)
	assert.Assert(t, is.Len(res.Stderr(), 0))
	assert.Equal(t, 0, res.ExitCode)
	return strings.TrimSpace(res.Stdout())
}