-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyurl_test.go
More file actions
89 lines (72 loc) · 2.15 KB
/
yurl_test.go
File metadata and controls
89 lines (72 loc) · 2.15 KB
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
package main
import (
"fmt"
"github.com/ThomasRooney/gexpect"
"github.com/eidge/yurl/testing/expect"
"net"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
// I don't really like this solution to do integration tests
// specially because it relies on yurl already beeing built.
// I haven't found a better solution yet, though.
var yurlCmd = "./yurl"
func startYurl(args ...string) *gexpect.ExpectSubprocess {
child, err := gexpect.Spawn(yurlCmd + " " + strings.Join(args, " "))
if err != nil {
panic(err)
}
return child
}
func TestYurlWithNoArgs(t *testing.T) {
yurl := startYurl()
defer yurl.Close()
// Expect help screen
match, _ := yurl.ExpectRegex("Usage:")
expect.Equal(t, match, true)
}
func TestYurlWithoutRequestName(t *testing.T) {
yurl := startYurl("config/fixtures/simple.yml")
defer yurl.Close()
match, _ := yurl.ExpectRegex("Requests in")
expect.Equal(t, match, true)
match, _ = yurl.ExpectRegex("example_post")
expect.Equal(t, match, true)
match, _ = yurl.ExpectRegex("example_get")
expect.Equal(t, match, true)
}
func TestYurlWithNonExistantFile(t *testing.T) {
yurl := startYurl("non_existant_yaml request_name")
defer yurl.Close()
match, _ := yurl.ExpectRegex("no such file")
expect.Equal(t, match, true)
}
func TestYurlWithNonExistantRequest(t *testing.T) {
yurl := startYurl("config/fixtures/simple.yml request_name")
defer yurl.Close()
match, _ := yurl.ExpectRegex("not found")
expect.Equal(t, match, true)
}
func TestYurlWithInvalidRequest(t *testing.T) {
yurl := startYurl("config/fixtures/invalid_request.yml request_name")
defer yurl.Close()
match, _ := yurl.ExpectRegex("Invalid request")
expect.Equal(t, match, true)
}
func TestYurlWithValidArguments(t *testing.T) {
// Start test server
server := httptest.NewUnstartedServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "it works")
}))
server.Listener, _ = net.Listen("tcp", ":8080")
server.Start()
defer server.Close()
// Run yurl against the test server
yurl := startYurl("config/fixtures/simple.yml integration_test")
defer yurl.Close()
match, _ := yurl.ExpectRegex("it works")
expect.Equal(t, match, true)
}