forked from parse-community/parse-cli
/
legacy_config_test.go
134 lines (119 loc) · 3.33 KB
/
legacy_config_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
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 main
import (
"io/ioutil"
"os"
"regexp"
"testing"
"github.com/facebookgo/ensure"
)
var defaulParseConfig = &parseConfig{
projectConfig: &projectConfig{
Type: legacy,
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 in a directory containing 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)
}