Skip to content

Commit

Permalink
make sure test server isn't already closed when running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed May 30, 2017
1 parent 6dce6be commit 0cfc908
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
14 changes: 9 additions & 5 deletions cmd/flowrunner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func runFlow(env utils.Environment, flowFilename string, contactFilename string,
}

// set up a mock server for webhook actions
func startTestHTTPServer() {
func newTestHTTPServer() *httptest.Server {
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cmd := r.URL.Query().Get("cmd")
defer r.Body.Close()
Expand All @@ -177,14 +177,18 @@ func startTestHTTPServer() {
log.Fatal(err)
}
server.Listener = l
server.Start()
defer server.Close()
serverURL = server.URL
return server
}

func TestFlows(t *testing.T) {
env := utils.NewDefaultEnvironment()
startTestHTTPServer()

server := newTestHTTPServer()
server.Start()
defer server.Close()

// save away our server URL so we can rewrite our URLs
serverURL = server.URL

for _, test := range flowTests {
testJSON, err := readFile("flows/", test.output)
Expand Down
28 changes: 8 additions & 20 deletions cmd/flowrunner/testdata/flows/all_actions_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,21 @@
"name": "Gender",
"value": "Male"
},
{
"type": "error",
"created_on": "2000-01-01T00:00:00.000000000-00:00",
"step": "",
"text": "Get http://127.0.0.1:49999/?cmd=success: dial tcp 127.0.0.1:49999: getsockopt: connection refused"
},
{
"type": "webhook",
"created_on": "2000-01-01T00:00:00.000000000-00:00",
"step": "",
"url": "http://127.0.0.1:49999/?cmd=success",
"status": "F",
"status_code": 0,
"status": "S",
"status_code": 200,
"request": "GET /?cmd=success HTTP/1.1\r\nHost: 127.0.0.1:49999\r\nUser-Agent: Go-http-client/1.1\r\nAccept-Encoding: gzip\r\n\r\n",
"response": ""
"response": "HTTP/1.1 200 OK\r\nContent-Length: 16\r\nContent-Type: text/plain; charset=utf-8\r\nDate: \r\n\r\n{ \"ok\": \"true\" }"
}
]
}
],
"status": "C",
"child": "c458a838-efa8-42d7-a655-3e4784bcbf5b",
"child": "c9943827-b80b-4e22-8e46-6be598049f4e",
"results": {
"gender": {
"node": "node1",
Expand All @@ -132,7 +126,7 @@
"contact": "contact1-test-4b7f-a34b-e37e31e86451",
"path": [],
"status": "C",
"parent": "2d17c317-93c1-497d-879d-3ed56cf1b0d4",
"parent": "746ab857-7354-4aa9-8b16-a9b62d23c4aa",
"results": {},
"created_on": "2000-01-01T00:00:00.000000000-00:00",
"modified_on": "2000-01-01T00:00:00.000000000-00:00",
Expand Down Expand Up @@ -216,21 +210,15 @@
"name": "Gender",
"value": "Male"
},
{
"type": "error",
"created_on": "2000-01-01T00:00:00.000000000-00:00",
"step": "",
"text": "Get http://127.0.0.1:49999/?cmd=success: dial tcp 127.0.0.1:49999: getsockopt: connection refused"
},
{
"type": "webhook",
"created_on": "2000-01-01T00:00:00.000000000-00:00",
"step": "",
"url": "http://127.0.0.1:49999/?cmd=success",
"status": "F",
"status_code": 0,
"status": "S",
"status_code": 200,
"request": "GET /?cmd=success HTTP/1.1\r\nHost: 127.0.0.1:49999\r\nUser-Agent: Go-http-client/1.1\r\nAccept-Encoding: gzip\r\n\r\n",
"response": ""
"response": "HTTP/1.1 200 OK\r\nContent-Length: 16\r\nContent-Type: text/plain; charset=utf-8\r\nDate: \r\n\r\n{ \"ok\": \"true\" }"
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/flowrunner/testdata/flows/subflow_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"type": "flow",
"flow": "flow2"
},
"child": "5a08f736-52ac-4934-9d6c-71e3d3929d17",
"child": "ec00435a-38a7-499a-9bf3-0ae8796d5e06",
"results": {},
"created_on": "2000-01-01T00:00:00.000000000-00:00",
"modified_on": "2000-01-01T00:00:00.000000000-00:00",
Expand Down Expand Up @@ -92,7 +92,7 @@
"wait": {
"type": "msg"
},
"parent": "c2bb899c-cccd-4e40-9ada-423a309c0c5f",
"parent": "b891f53a-9f65-400b-9d48-7fcbfba55e5e",
"results": {},
"created_on": "2000-01-01T00:00:00.000000000-00:00",
"modified_on": "2000-01-01T00:00:00.000000000-00:00",
Expand Down Expand Up @@ -213,7 +213,7 @@
"contact": "contact1-test-4b7f-a34b-e37e31e86451",
"text": "Ryan Lewis"
},
"parent": "c2bb899c-cccd-4e40-9ada-423a309c0c5f",
"parent": "b891f53a-9f65-400b-9d48-7fcbfba55e5e",
"results": {
"name": {
"node": "flow2-node1",
Expand Down Expand Up @@ -290,7 +290,7 @@
}
],
"status": "C",
"child": "5a08f736-52ac-4934-9d6c-71e3d3929d17",
"child": "ec00435a-38a7-499a-9bf3-0ae8796d5e06",
"results": {},
"created_on": "2000-01-01T00:00:00.000000000-00:00",
"modified_on": "2000-01-01T00:00:00.000000000-00:00",
Expand Down

0 comments on commit 0cfc908

Please sign in to comment.