forked from parse-community/parse-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
73 lines (63 loc) · 1.82 KB
/
main_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
package main
import (
"io/ioutil"
"net/http"
"regexp"
"testing"
"github.com/ParsePlatform/parse-cli/parsecli"
"github.com/facebookgo/ensure"
"github.com/facebookgo/jsonpipe"
"github.com/facebookgo/parse"
)
func TestNewClientInvalidServerURL(t *testing.T) {
t.Parallel()
c, err := parsecli.NewParseAPIClient(&parsecli.Env{Server: ":"})
ensure.True(t, c == nil)
ensure.Err(t, err, regexp.MustCompile("invalid server URL"))
}
func TestIsSupportedWarning(t *testing.T) {
t.Parallel()
h := parsecli.NewHarness(t)
defer h.Stop()
ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
ensure.DeepEqual(t, r.URL.Path, "/1/supported")
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(
jsonpipe.Encode(
map[string]string{"warning": "please update"},
),
),
}, nil
})
h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
message, err := checkIfSupported(h.Env, "2.0.2", "parse")
ensure.Nil(t, err)
ensure.DeepEqual(t, message, "please update")
}
func TestIsSupportedError(t *testing.T) {
t.Parallel()
h := parsecli.NewHarness(t)
defer h.Stop()
ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
ensure.DeepEqual(t, r.URL.Path, "/1/supported")
return &http.Response{
StatusCode: http.StatusBadRequest,
Body: ioutil.NopCloser(
jsonpipe.Encode(
map[string]string{"error": "not supported"},
),
),
}, nil
})
h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
_, err := checkIfSupported(h.Env, "2.0.2", "parse")
ensure.Err(t, err, regexp.MustCompile("not supported"))
}
// this just exists to make code coverage less noisy.
func TestRootCommand(t *testing.T) {
t.Parallel()
h := parsecli.NewHarness(t)
defer h.Stop()
parseRootCmd(h.Env)
}