forked from containers/storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
44 lines (39 loc) · 918 Bytes
/
utils_test.go
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
package storage
import (
"testing"
"gotest.tools/assert"
)
func TestValidStoragePathFormat(t *testing.T) {
// Given
expectErr := "Unrecognized environment variable"
invalidPaths := []struct {
path string
expect string
}{
{"$", expectErr},
{"$HOMEDIR", expectErr},
{"$HOMEdir", expectErr},
{"/test/$HOMEDIR/$USERNAME/$UID", expectErr},
{"/test/$HOME/$USERNAME/$UID", expectErr},
{"/test/$HOME/$USER/$UIDNUM", expectErr},
}
validPaths := []string{
"$HOME",
"$HOME/",
"/test/path",
"/test/$HOME",
"/test/$HOME/path",
"/test/$HOME/$USER/$UID",
"/test/$HOME/$USER/$UID/path",
"$HOME/$USER/$UID/path",
}
// Then
for _, conf := range invalidPaths {
err := validRootlessStoragePathFormat(conf.path)
assert.Error(t, err, "Unrecognized environment variable")
}
for _, path := range validPaths {
err := validRootlessStoragePathFormat(path)
assert.NilError(t, err)
}
}