aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/initmkdir_test.go
blob: 4bec4fa434719a96614323497092729379e0f67f (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
43
44
45
46
47
package container

import (
	"os"
	"testing"

	"hakurei.app/container/check"
	"hakurei.app/container/stub"
)

func TestMkdirOp(t *testing.T) {
	t.Parallel()

	checkOpBehaviour(t, []opBehaviourTestCase{
		{"success", new(Params), &MkdirOp{
			Path: check.MustAbs("/.hakurei"),
			Perm: 0500,
		}, nil, nil, []stub.Call{
			call("mkdirAll", stub.ExpectArgs{"/sysroot/.hakurei", os.FileMode(0500)}, nil, nil),
		}, nil},
	})

	checkOpsValid(t, []opValidTestCase{
		{"nil", (*MkdirOp)(nil), false},
		{"zero", new(MkdirOp), false},
		{"valid", &MkdirOp{Path: check.MustAbs("/.hakurei")}, true},
	})

	checkOpsBuilder(t, []opsBuilderTestCase{
		{"etc", new(Ops).Mkdir(check.MustAbs("/etc/"), 0), Ops{
			&MkdirOp{Path: check.MustAbs("/etc/")},
		}},
	})

	checkOpIs(t, []opIsTestCase{
		{"zero", new(MkdirOp), new(MkdirOp), false},
		{"path differs", &MkdirOp{Path: check.MustAbs("/"), Perm: 0755}, &MkdirOp{Path: check.MustAbs("/etc/"), Perm: 0755}, false},
		{"perm differs", &MkdirOp{Path: check.MustAbs("/")}, &MkdirOp{Path: check.MustAbs("/"), Perm: 0755}, false},
		{"equals", &MkdirOp{Path: check.MustAbs("/")}, &MkdirOp{Path: check.MustAbs("/")}, true},
	})

	checkOpMeta(t, []opMetaTestCase{
		{"etc", &MkdirOp{
			Path: check.MustAbs("/etc/"),
		}, "creating", `directory "/etc/" perm ----------`},
	})
}