Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.

Commit 649c5cc

Browse files
author
Pavan Kumar
committed
[tests] add more tests to improve coverage
1 parent 6862655 commit 649c5cc

File tree

6 files changed

+128
-1
lines changed

6 files changed

+128
-1
lines changed

apps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (a *apps) createApp(e *env, givenName string) (*app, error) {
248248
}
249249

250250
if _, ok := appNames[appName]; ok {
251-
fmt.Fprintf(e.Out,
251+
fmt.Fprintf(e.Err,
252252
`Hey! you already created an app named %q.
253253
The apps associated with your account:
254254
%s

apps_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,20 @@ RevokeSessionOnPasswordChange true
259259
`)
260260
}
261261

262+
func TestCreateNewAppNameTaken(t *testing.T) {
263+
t.Parallel()
264+
265+
h, _ := newAppHarness(t)
266+
defer h.Stop()
267+
268+
a := defaultApps
269+
270+
h.env.In = ioutil.NopCloser(strings.NewReader("A\nD"))
271+
_, err := a.createApp(h.env, "")
272+
ensure.Nil(t, err)
273+
ensure.StringContains(t, h.Err.String(), "already created an app")
274+
}
275+
262276
func TestNoPanicAppCreate(t *testing.T) {
263277
t.Parallel()
264278
h := newHarness(t)

list_cmd_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"io/ioutil"
5+
"strings"
46
"testing"
57

68
"github.com/facebookgo/ensure"
@@ -70,3 +72,15 @@ func TestPrintListNoApps(t *testing.T) {
7072
n.cloneSampleCloudCode(h.env, true)
7173
ensure.Nil(t, l.printListOfApps(h.env))
7274
}
75+
76+
func TestRunListCmd(t *testing.T) {
77+
t.Parallel()
78+
79+
h, _ := newAppHarness(t)
80+
defer h.Stop()
81+
82+
l := &listCmd{}
83+
h.env.In = ioutil.NopCloser(strings.NewReader("email\npassword\n"))
84+
ensure.Nil(t, l.run(h.env, []string{"A"}))
85+
ensure.StringContains(t, h.Out.String(), `Properties of the app "A"`)
86+
}

main_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"path/filepath"
1212
"regexp"
13+
"strings"
1314
"testing"
1415

1516
"github.com/facebookgo/clock"
@@ -375,3 +376,31 @@ func TestMultiErrorString(t *testing.T) {
375376
ensure.StringContains(t, errStr, `parse: api error with code=1 and message="message"`)
376377
ensure.StringContains(t, errStr, ".go")
377378
}
379+
380+
func TestRunWithContext(t *testing.T) {
381+
t.Parallel()
382+
383+
h := newHarness(t)
384+
h.makeEmptyRoot()
385+
defer h.Stop()
386+
387+
n := &newCmd{}
388+
h.env.Type = parseFormat
389+
h.env.In = ioutil.NopCloser(strings.NewReader("\n"))
390+
_, err := n.setupSample(h.env,
391+
"yolo",
392+
&parseAppConfig{
393+
ApplicationID: "yolo-id",
394+
MasterKey: "yoda",
395+
},
396+
false,
397+
false,
398+
)
399+
ensure.Nil(t, err)
400+
401+
dummy := func(e *env, c *context) error {
402+
ensure.DeepEqual(t, c.AppConfig.getApplicationID(), "yolo-id")
403+
return nil
404+
}
405+
runWithAppClient(h.env, dummy)
406+
}

migrate_cmd_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package main
22

33
import (
4+
"io/ioutil"
5+
"os"
6+
"path/filepath"
47
"regexp"
8+
"strings"
59
"testing"
610

711
"github.com/facebookgo/ensure"
@@ -76,3 +80,51 @@ func TestUpgradeLegacyWithEmail(t *testing.T) {
7680
ensure.DeepEqual(t, config.Applications["app"].MasterKey, "")
7781
ensure.DeepEqual(t, config.getProjectConfig().ParserEmail, "test@email.com")
7882
}
83+
84+
func TestRunMigrateCmd(t *testing.T) {
85+
t.Parallel()
86+
87+
h := newHarness(t)
88+
h.makeEmptyRoot()
89+
defer h.Stop()
90+
91+
n := &newCmd{}
92+
h.env.Type = parseFormat
93+
h.env.In = ioutil.NopCloser(strings.NewReader("\n"))
94+
_, err := n.setupSample(h.env,
95+
"yolo",
96+
&parseAppConfig{
97+
ApplicationID: "yolo-id",
98+
MasterKey: "yoda",
99+
},
100+
false,
101+
false,
102+
)
103+
ensure.Nil(t, err)
104+
105+
m := &migrateCmd{}
106+
err = m.run(h.env)
107+
ensure.Err(t, err, regexp.MustCompile("Already using the preferred config format"))
108+
109+
ensure.Nil(t, os.Remove(filepath.Join(h.env.Root, parseLocal)))
110+
ensure.Nil(t, os.Remove(filepath.Join(h.env.Root, parseProject)))
111+
112+
ensure.Nil(t, os.MkdirAll(filepath.Join(h.env.Root, configDir), 0755))
113+
ensure.Nil(t,
114+
ioutil.WriteFile(
115+
filepath.Join(h.env.Root, legacyConfigFile),
116+
[]byte(`{
117+
"applications": {
118+
"yolo": {
119+
"applicationId": "yolo-id",
120+
"masterKey": "yoda"
121+
}
122+
}
123+
}`),
124+
0600,
125+
),
126+
)
127+
128+
ensure.Nil(t, m.run(h.env))
129+
ensure.StringContains(t, h.Out.String(), "Successfully migrated")
130+
}

symbols_cmd_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"regexp"
5+
"testing"
6+
7+
"github.com/facebookgo/ensure"
8+
)
9+
10+
func TestRunSymbolsCmd(t *testing.T) {
11+
t.Parallel()
12+
13+
h := newHarness(t)
14+
defer h.Stop()
15+
16+
s := &symbolsCmd{}
17+
ensure.Err(t, s.run(h.env, nil), regexp.MustCompile("Please specify path"))
18+
}

0 commit comments

Comments
 (0)