This repository was archived by the owner on Jan 16, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathlegacy_config_test.go
More file actions
134 lines (119 loc) · 3.33 KB
/
Copy pathlegacy_config_test.go
File metadata and controls
134 lines (119 loc) · 3.33 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package parsecli
import (
"io/ioutil"
"os"
"regexp"
"testing"
"github.com/facebookgo/ensure"
)
var defaultParseConfig = &ParseConfig{
ProjectConfig: &ProjectConfig{
Type: LegacyParseFormat,
Parse: &ParseProjectConfig{},
},
}
func TestConfigAddAlias(t *testing.T) {
t.Parallel()
const name = "foo"
const link = "bar"
c := ParseConfig{Applications: map[string]*ParseAppConfig{link: {}}}
ensure.Nil(t, c.AddAlias(name, link))
ensure.DeepEqual(t, c.Applications, map[string]*ParseAppConfig{
link: {},
name: {Link: link},
})
}
func TestConfigAddAliasBadLink(t *testing.T) {
t.Parallel()
const name = "foo"
const link = "bar"
c := ParseConfig{}
ensure.Err(t, c.AddAlias(name, link), regexp.MustCompile("wasn't found"))
}
func TestConfigAddAliasDupe(t *testing.T) {
t.Parallel()
const name = "foo"
const link = "bar"
c := ParseConfig{Applications: map[string]*ParseAppConfig{link: {}}}
ensure.Nil(t, c.AddAlias(name, link))
ensure.Err(t, c.AddAlias(name, link), regexp.MustCompile("has already been added"))
}
func TestConfigSetDefault(t *testing.T) {
t.Parallel()
const name = "foo"
c := ParseConfig{Applications: map[string]*ParseAppConfig{name: {}}}
ensure.Nil(t, c.SetDefaultApp(name))
ensure.DeepEqual(t, c.Applications, map[string]*ParseAppConfig{
name: {},
DefaultKey: {Link: name},
})
}
func TestConfigApp(t *testing.T) {
t.Parallel()
const name = "foo"
c := ParseConfig{Applications: map[string]*ParseAppConfig{name: {}}}
ac, err := c.App(name)
ensure.Nil(t, err)
ensure.DeepEqual(t, ac, &ParseAppConfig{})
}
func TestConfigAppNotFound(t *testing.T) {
t.Parallel()
const name = "foo"
c := ParseConfig{Applications: map[string]*ParseAppConfig{}}
ac, err := c.App(name)
ensure.True(t, ac == nil)
ensure.Err(t, err, regexp.MustCompile(`App "foo" wasn't found`))
}
func TestConfigAppDefaultNotFound(t *testing.T) {
t.Parallel()
c := ParseConfig{Applications: map[string]*ParseAppConfig{}}
ac, err := c.App(DefaultKey)
ensure.True(t, ac == nil)
ensure.Err(t, err, regexp.MustCompile("No default app configured"))
}
func TestConfigAppLink(t *testing.T) {
t.Parallel()
const name = "foo"
const link = "bar"
expected := &ParseAppConfig{ApplicationID: "xyz"}
c := ParseConfig{Applications: map[string]*ParseAppConfig{
link: expected,
name: {Link: link},
}}
ac, err := c.App(name)
ensure.Nil(t, err)
ensure.DeepEqual(t, ac, expected)
}
func TestConfigMissing(t *testing.T) {
t.Parallel()
dir, err := ioutil.TempDir("", "parse-cli-config-")
ensure.Nil(t, err)
defer os.RemoveAll(dir)
c, err := ConfigFromDir(dir)
ensure.True(t, c == nil)
ensure.Err(t, err, regexp.MustCompile("Command must be run inside a Parse project."))
}
func TestConfigGlobalMalformed(t *testing.T) {
t.Parallel()
dir := makeDirWithConfig(t, "foo")
defer os.RemoveAll(dir)
c, err := ConfigFromDir(dir)
ensure.True(t, c == nil)
ensure.Err(t, err, regexp.MustCompile("is not valid JSON"))
}
func TestConfigGlobalEmpty(t *testing.T) {
t.Parallel()
dir := makeDirWithConfig(t, "")
defer os.RemoveAll(dir)
c, err := ConfigFromDir(dir)
ensure.True(t, c == nil)
ensure.Err(t, err, regexp.MustCompile("is not valid JSON"))
}
func TestConfigEmptyGlobalOnly(t *testing.T) {
t.Parallel()
dir := makeDirWithConfig(t, "{}")
defer os.RemoveAll(dir)
c, err := ConfigFromDir(dir)
ensure.Nil(t, err)
ensure.DeepEqual(t, c.GetNumApps(), 0)
}