forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathensure_dir_test.go
More file actions
89 lines (79 loc) · 3 KB
/
Copy pathensure_dir_test.go
File metadata and controls
89 lines (79 loc) · 3 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2023 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package interfaces_test
import (
. "gopkg.in/check.v1"
"github.com/snapcore/snapd/interfaces"
)
type ensureDirSuite struct{}
var _ = Suite(&ensureDirSuite{})
func (s *ensureDirSuite) TestValidateHappy(c *C) {
testMap := map[string]struct {
EnsureDir interfaces.EnsureDirSpec
}{
"Abs1": {interfaces.EnsureDirSpec{MustExistDir: "/", EnsureDir: "/dir"}},
"Abs2": {interfaces.EnsureDirSpec{MustExistDir: "/dir1", EnsureDir: "/dir1/dir2"}},
"Env1": {interfaces.EnsureDirSpec{MustExistDir: "$HOME", EnsureDir: "$HOME/dir"}},
"Env2": {interfaces.EnsureDirSpec{MustExistDir: "$HOME/dir1", EnsureDir: "$HOME/dir1/dir2"}},
}
for name, test := range testMap {
c.Check(test.EnsureDir.Validate(), IsNil, Commentf("test: %q", name))
}
}
func (s *ensureDirSuite) TestValidateErrors(c *C) {
testMap := map[string]struct {
EnsureDir interfaces.EnsureDirSpec
ErrorMsg string
}{
"Unclean1": {
interfaces.EnsureDirSpec{MustExistDir: "", EnsureDir: "/dir"},
`directory that must exist "" is not a clean path`,
},
"Unclean2": {
interfaces.EnsureDirSpec{MustExistDir: "/dir", EnsureDir: "/../"},
`directory to ensure "/../" is not a clean path`,
},
"BadEnv1": {
interfaces.EnsureDirSpec{MustExistDir: "$SNAP_COMMON", EnsureDir: "$SNAP_COMMON/dir"},
`directory that must exist "\$SNAP_COMMON" prefix "\$SNAP_COMMON" is not allowed`,
},
"BadEnv2": {
interfaces.EnsureDirSpec{MustExistDir: "$HOME", EnsureDir: "$SNAP_COMMON/dir"},
`directory to ensure "\$SNAP_COMMON/dir" prefix "\$SNAP_COMMON" is not allowed`,
},
"Relative1": {
interfaces.EnsureDirSpec{MustExistDir: "dir1", EnsureDir: "$HOME/dir2"},
`directory that must exist "dir1" is not an absolute path`,
},
"Relative2": {
interfaces.EnsureDirSpec{MustExistDir: "$HOME", EnsureDir: "dir1/dir2"},
`directory to ensure "dir1/dir2" is not an absolute path`,
},
"BadParent1": {
interfaces.EnsureDirSpec{MustExistDir: "$HOME", EnsureDir: "$HOME"},
`directory that must exist "\$HOME" is not a parent of directory to ensure "\$HOME"`,
},
"BadParent2": {
interfaces.EnsureDirSpec{MustExistDir: "/dir1", EnsureDir: "/dir2/dir1"},
`directory that must exist "/dir1" is not a parent of directory to ensure "/dir2/dir1"`,
},
}
for name, test := range testMap {
c.Check(test.EnsureDir.Validate(), ErrorMatches, test.ErrorMsg, Commentf("test: %q", name))
}
}