forked from parse-community/parse-cli
/
develop_cmd_test.go
101 lines (84 loc) · 1.94 KB
/
develop_cmd_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
package main
import (
"errors"
"fmt"
"io/ioutil"
"net"
"path/filepath"
"testing"
"time"
"github.com/facebookgo/ensure"
)
func TestContDeploy(t *testing.T) {
t.Parallel()
h := createParseProject(t)
defer h.Stop()
deployer := deployFunc(func(parseVersion string,
prevDeplInfo *deployInfo,
forDevelop bool,
e *env) (*deployInfo, error) {
return &deployInfo{}, nil
})
done := make(chan struct{})
go func() {
h.Clock.Add(time.Second)
close(done)
}()
first := make(chan struct{})
(&developCmd{}).contDeploy(h.env, deployer, first, done)
_, opened := <-first
ensure.False(t, opened)
}
func TestContDeployConfigErr(t *testing.T) {
t.Parallel()
h := createParseProject(t)
defer h.Stop()
ensure.Nil(t,
ioutil.WriteFile(
filepath.Join(h.env.Root, legacyConfigFile),
[]byte("}"),
0600,
),
)
h.env.Type = legacy
deployer := deployFunc(func(parseVersion string,
prevDeplInfo *deployInfo,
forDevelop bool,
e *env) (*deployInfo, error) {
return &deployInfo{}, nil
})
done := make(chan struct{})
go func() {
h.Clock.Add(5 * time.Second)
close(done)
}()
first := make(chan struct{})
(&developCmd{}).contDeploy(h.env, deployer, first, done)
_, opened := <-first
ensure.False(t, opened)
ensure.StringContains(
t,
h.Err.String(),
fmt.Sprintf(
`Config malformed.
Please fix your config file in %s and try again.
`,
filepath.Join(h.env.Root, legacyConfigFile),
),
)
}
func TestHandleError(t *testing.T) {
t.Parallel()
h := newHarness(t)
defer h.Stop()
d := &developCmd{}
netErr := &net.OpError{Err: errors.New("network")}
sleep := func(d time.Duration) {}
ensure.DeepEqual(t, d.handleError(h.env, netErr, sleep), netErr)
ensure.DeepEqual(t, h.Err.String(), "Flaky network. Waiting 20s before trying to fetch logs again.")
h.Out.Reset()
h.Err.Reset()
otherErr := errors.New("other")
ensure.DeepEqual(t, d.handleError(h.env, otherErr, sleep), otherErr)
ensure.DeepEqual(t, h.Err.Len(), 0)
}