-
Notifications
You must be signed in to change notification settings - Fork 0
/
swell_test.go
93 lines (76 loc) · 2.48 KB
/
swell_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
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
90
91
92
93
package main
import (
"flag"
"os"
// "github.com/Sirupsen/logrus"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
var CURRENT_DIR, _ = os.Getwd()
func TestMain(t *testing.T) {
flag.Parse()
// Create a local directory that matches the name of the default profiles
// directory. This will be automatically deleted again by the gotest
// executable when it clears all test files.
//
// Additionally, create a profile called "first."
os.Mkdir(*PROFILES_PATH, os.ModeDir|0777)
os.Mkdir(*PROFILES_PATH+"first", os.ModeDir|os.ModePerm)
Convey("directories actually exists?", t, func() {
workingDir, _ := os.Getwd()
info, err := os.Stat(workingDir + "/" + *PROFILES_PATH)
So(err, ShouldBeNil)
So(info.IsDir(), ShouldEqual, true)
info, err = os.Stat(workingDir + "/" + *PROFILES_PATH + "first")
So(err, ShouldBeNil)
So(info.IsDir(), ShouldEqual, true)
})
}
/****
** config.go:GetConfigPath
****/
func TestGetProfilesPath(t *testing.T) {
// When no special path is provided, this should return the default in
// the current directory.
// TODO: need this test but the testing directory mis-match is screwing it up atm
/*
Convey("returns correct default path", t, func() {
path, err := GetProfilesPath(*PROFILES_PATH)
So(err, ShouldBeNil)
So(path, ShouldEqual, CURRENT_DIR + "/" + *PROFILES_PATH)
})
*/
/*
Convey("rejects paths that lead to files", t, func() {
})
*/
// When an absolute path is provided, don't append a bunch of garbage
// in front of it for some reason. The output should be the same as
// the input in this case (unless the file doesn't exist, then it should
// return an error.
Convey("doesn't mangle absolute directories", t, func() {
path, err := GetProfilesPath(CURRENT_DIR)
So(err, ShouldBeNil)
So(path, ShouldEqual, CURRENT_DIR)
})
Convey("can detect existing absolute paths", t, func() {
path, err := GetProfilesPath(CURRENT_DIR + "/profiles")
So(err, ShouldBeNil)
So(path, ShouldEqual, CURRENT_DIR+"/profiles")
})
Convey("returns an error when the directory doesn't exist", t, func() {
path, err := GetProfilesPath("where-is-this")
So(err, ShouldNotBeNil)
So(path, ShouldEqual, "")
})
}
func TestLoadProfiles(t *testing.T) {
Convey("detects all profiles", t, func() {
path, err := GetProfilesPath(CURRENT_DIR + "/profiles")
profiles, err := LoadProfiles([]string{}, SwellConfig{
ProfilesPath: path,
})
So(err, ShouldBeNil)
So(len(profiles), ShouldEqual, 1)
})
}