summaryrefslogtreecommitdiff
path: root/libpod/container_internal_linux_test.go
blob: 078cc53a73c9f870c5997a23aacfe6f2221655f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// +build linux

package libpod

import (
	"io/ioutil"
	"os"
	"testing"

	spec "github.com/opencontainers/runtime-spec/specs-go"
	"github.com/stretchr/testify/assert"
)

func TestGenerateUserPasswdEntry(t *testing.T) {
	dir, err := ioutil.TempDir("", "libpod_test_")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(dir)

	c := Container{
		config: &ContainerConfig{
			User: "123:456",
			Spec: &spec.Spec{},
		},
		state: &ContainerState{
			Mountpoint: "/does/not/exist/tmp/",
		},
	}
	user, err := c.generateUserPasswdEntry()
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, user, "123:x:123:456:container user:/:/bin/sh\n")

	c.config.User = "567"
	user, err = c.generateUserPasswdEntry()
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, user, "567:x:567:0:container user:/:/bin/sh\n")
}