-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig_test.go
More file actions
66 lines (55 loc) · 1.84 KB
/
config_test.go
File metadata and controls
66 lines (55 loc) · 1.84 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
package conf
import (
"io/ioutil"
"os"
"os/user"
"testing"
"github.com/deis/builder/pkg/sys"
)
func TestGetStorageParams(t *testing.T) {
usr, err := user.Current()
if err != nil {
t.Logf("could not retrieve current user: %v", err)
t.SkipNow()
}
if usr.Uid != "0" {
t.Logf("current user does not have UID of zero (got %s) "+
"so cannot create storage cred location, skipping", usr.Uid)
t.SkipNow()
}
if err := os.MkdirAll(storageCredLocation, os.ModeDir); err != nil {
t.Fatalf("could not create storage cred location: %v", err)
}
// start by writing out a file to storageCredLocation
data := []byte("hello world\n")
if err := ioutil.WriteFile(storageCredLocation+"foo", data, 0644); err != nil {
t.Fatalf("could not write file to storage cred location: %v", err)
}
params, err := GetStorageParams(sys.NewFakeEnv())
if err != nil {
t.Errorf("received error while retrieving storage params: %v", err)
}
val, ok := params["foo"]
if !ok {
t.Error("key foo does not exist in storage params")
}
if val != string(data) {
t.Errorf("expected: %s got: %s", string(data), val)
}
// create a directory inside storage cred location, expecting it to pass
if err := os.Mkdir(storageCredLocation+"bar", os.ModeDir); err != nil {
t.Fatalf("could not create dir %s: %v", storageCredLocation+"bar", err)
}
_, err = GetStorageParams(sys.NewFakeEnv())
if err != nil {
t.Errorf("received error while retrieving storage params: %v", err)
}
// create the special "..data" directory symlink, expecting it to pass
if err := os.Symlink(storageCredLocation+"bar", storageCredLocation+"..data"); err != nil {
t.Fatalf("could not create dir symlink ..data -> %s: %v", storageCredLocation+"bar", err)
}
_, err = GetStorageParams(sys.NewFakeEnv())
if err != nil {
t.Errorf("received error while retrieving storage params: %v", err)
}
}