This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
configure_test.go
152 lines (130 loc) · 3.98 KB
/
configure_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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"io/ioutil"
"path/filepath"
"regexp"
"strings"
"testing"
"github.com/ParsePlatform/parse-cli/parsecli"
"github.com/facebookgo/ensure"
)
func TestConfigureAccountKey(t *testing.T) {
t.Parallel()
h := parsecli.NewTokenHarness(t)
defer h.Stop()
c := configureCmd{login: parsecli.Login{TokenReader: strings.NewReader("")}}
h.Env.In = ioutil.NopCloser(strings.NewReader("token\n"))
ensure.Nil(t, c.accountKey(h.Env))
ensure.StringContains(
t,
h.Out.String(),
`
Input your account key or press ENTER to generate a new one.
`)
h.Env.In = ioutil.NopCloser(strings.NewReader("invalid\n"))
ensure.Err(t, c.accountKey(h.Env), regexp.MustCompile("is not valid"))
ensure.DeepEqual(t,
h.Err.String(),
"Could not store credentials. Please try again.\n\n",
)
h.Env.Server = "http://api.parse.com/1/"
c.tokenReader = strings.NewReader(
`machine api.parse.com#email
login default
password token2
`,
)
h.Err.Reset()
h.Env.In = ioutil.NopCloser(strings.NewReader("token\n"))
ensure.Nil(t, c.accountKey(h.Env))
ensure.DeepEqual(t, h.Err.String(),
`Note: this operation will overwrite the account key:
"*oken"
for email: "email"
`)
h.Env.Server = "http://api.parse.com/1/"
c.tokenReader = strings.NewReader(
`machine api.parse.com#email
login default
password token2
`,
)
c.isDefault = true
h.Err.Reset()
h.Env.In = ioutil.NopCloser(strings.NewReader("token\n"))
ensure.Nil(t, c.accountKey(h.Env))
ensure.DeepEqual(t, h.Err.String(), "")
h.Env.Server = "http://api.parse.com/1/"
c.tokenReader = strings.NewReader(
`machine api.parse.com
login default
password token2
`,
)
c.isDefault = true
h.Err.Reset()
h.Env.In = ioutil.NopCloser(strings.NewReader("token\n"))
ensure.Nil(t, c.accountKey(h.Env))
ensure.DeepEqual(t, h.Err.String(), "Note: this operation will overwrite the default account key\n")
h.Env.Server = "http://api.parse.com/1/"
c.tokenReader = strings.NewReader(
`machine api.parse.com
login default
password token2
`,
)
h.Err.Reset()
c.isDefault = false
h.Env.In = ioutil.NopCloser(strings.NewReader("token\n"))
ensure.Nil(t, c.accountKey(h.Env))
ensure.DeepEqual(t, h.Err.String(), "")
}
func TestParserEmail(t *testing.T) {
t.Parallel()
h := parsecli.NewTokenHarness(t)
h.MakeEmptyRoot()
defer h.Stop()
ensure.Nil(t, parsecli.CreateConfigWithContent(filepath.Join(h.Env.Root, parsecli.ParseLocal), "{}"))
ensure.Nil(t,
parsecli.CreateConfigWithContent(
filepath.Join(h.Env.Root, parsecli.ParseProject),
`{"project_type": 1}`,
),
)
var c configureCmd
ensure.Nil(t, c.parserEmail(h.Env, []string{"email2"}))
ensure.DeepEqual(
t,
h.Out.String(),
`Successfully configured email for current project to: "email2"
`,
)
ensure.Err(t, c.parserEmail(h.Env, nil), regexp.MustCompile("Invalid args:"))
ensure.Err(t, c.parserEmail(h.Env, []string{"a", "b"}), regexp.MustCompile("Invalid args:"))
}
func TestProjectType(t *testing.T) {
t.Parallel()
h := parsecli.NewHarness(t)
defer h.Stop()
h.MakeEmptyRoot()
ensure.Nil(t, parsecli.CloneSampleCloudCode(h.Env, false))
c := &configureCmd{}
err := c.projectType(h.Env, []string{"1", "2"})
ensure.Err(t, err, regexp.MustCompile("only an optional project type argument is expected"))
h.Env.In = ioutil.NopCloser(strings.NewReader("invalid\n"))
err = c.projectType(h.Env, nil)
ensure.StringContains(t, h.Err.String(), "Invalid selection. Please enter a number")
ensure.Err(t, err, regexp.MustCompile("Could not make a selection. Please try again."))
h.Err.Reset()
h.Out.Reset()
h.Env.In = ioutil.NopCloser(strings.NewReader("0\n"))
err = c.projectType(h.Env, nil)
ensure.StringContains(t, h.Err.String(), "Please enter a number between 1 and")
ensure.Err(t, err, regexp.MustCompile("Could not make a selection. Please try again."))
h.Err.Reset()
h.Out.Reset()
h.Env.In = ioutil.NopCloser(strings.NewReader("1\n"))
err = c.projectType(h.Env, nil)
ensure.StringContains(t, h.Out.String(), "Successfully set project type to: parse")
ensure.Nil(t, err)
}