-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathopen_test.go
82 lines (68 loc) · 2.4 KB
/
open_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
package main
import (
"strings"
"testing"
"code.cloudfoundry.org/cli/plugin/pluginfakes"
. "github.com/smartystreets/goconvey/convey"
)
var (
cliConn *pluginfakes.FakeCliConnection
)
func TestNoApp(t *testing.T) {
setup()
Convey("checkArgs should not return error with open test", t, func() {
err := checkArgs(cliConn, []string{"open", "test"})
So(err, ShouldBeNil)
})
Convey("checkArgs should not return error with service-open test", t, func() {
err := checkArgs(cliConn, []string{"service-open", "test"})
So(err, ShouldBeNil)
})
Convey("checkArgs should return error with open", t, func() {
err := checkArgs(cliConn, []string{"open"})
So(err, ShouldNotBeNil)
})
Convey("checkArgs should return error with service-open", t, func() {
err := checkArgs(cliConn, []string{"service-open"})
So(err, ShouldNotBeNil)
})
}
func TestNoRoutes(t *testing.T) {
Convey("getUrlFromOuput should return nil if route exists", t, func() {
input := []string{"urls: google.com"}
out, err := getUrlFromOutput(input)
So(err, ShouldBeNil)
So(out[0], ShouldEqual, "https://google.com")
})
Convey("getUrlFromOuput should return error if no route exists", t, func() {
input := []string{"urls: "}
out, err := getUrlFromOutput(input)
So(err, ShouldNotBeNil)
So(out[0], ShouldEqual, "")
})
Convey("getUrlFromOuput should handle multiple routes", t, func() {
input := []string{"urls: google.com, apple.com, github.com"}
out, err := getUrlFromOutput(input)
So(err, ShouldBeNil)
So(out[0], ShouldEqual, "https://google.com")
So(out[1], ShouldEqual, "https://apple.com")
So(out[2], ShouldEqual, "https://github.com")
})
}
func TestRoutesMenu(t *testing.T) {
Convey("multiRoutesMenu should return url if there is one route", t, func() {
input := []string{"https://google.com"}
So(multiRoutesMenu(strings.NewReader(""), input), ShouldEqual, "https://google.com")
})
Convey("multiRoutesMenu should return 1nd url if first route is chosen", t, func() {
input := []string{"https://google.com", "https://apple.com"}
So(multiRoutesMenu(strings.NewReader("1"), input), ShouldEqual, "https://google.com")
})
Convey("multiRoutesMenu should return 2nd url if second route is chosen", t, func() {
input := []string{"https://google.com", "https://apple.com"}
So(multiRoutesMenu(strings.NewReader("2"), input), ShouldEqual, "https://apple.com")
})
}
func setup() {
cliConn = &pluginfakes.FakeCliConnection{}
}