github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/drivers/docker/utils_unix_test.go (about) 1 // +build darwin dragonfly freebsd linux netbsd openbsd solaris 2 3 package docker 4 5 import ( 6 "path/filepath" 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestValidateCgroupPermission(t *testing.T) { 13 positiveCases := []string{ 14 "r", 15 "rw", 16 "rwm", 17 "mr", 18 "mrw", 19 "", 20 } 21 22 for _, c := range positiveCases { 23 t.Run("positive case: "+c, func(t *testing.T) { 24 require.True(t, validateCgroupPermission(c)) 25 }) 26 } 27 28 negativeCases := []string{ 29 "q", 30 "asdf", 31 "rq", 32 } 33 34 for _, c := range negativeCases { 35 t.Run("negative case: "+c, func(t *testing.T) { 36 require.False(t, validateCgroupPermission(c)) 37 }) 38 } 39 } 40 41 func TestExpandPath(t *testing.T) { 42 cases := []struct { 43 base string 44 target string 45 expected string 46 }{ 47 {"/tmp/alloc/task", ".", "/tmp/alloc/task"}, 48 {"/tmp/alloc/task", "..", "/tmp/alloc"}, 49 50 {"/tmp/alloc/task", "d1/d2", "/tmp/alloc/task/d1/d2"}, 51 {"/tmp/alloc/task", "../d1/d2", "/tmp/alloc/d1/d2"}, 52 {"/tmp/alloc/task", "../../d1/d2", "/tmp/d1/d2"}, 53 54 {"/tmp/alloc/task", "/home/user", "/home/user"}, 55 {"/tmp/alloc/task", "/home/user/..", "/home"}, 56 } 57 58 for _, c := range cases { 59 t.Run(c.expected, func(t *testing.T) { 60 require.Equal(t, c.expected, filepath.ToSlash(expandPath(c.base, c.target))) 61 }) 62 } 63 }