From 0cfc908a2a7022aca83a2db3c21dd8e89a24d19d Mon Sep 17 00:00:00 2001 From: Nic Pottier Date: Tue, 30 May 2017 11:03:58 -0500 Subject: [PATCH] make sure test server isn't already closed when running tests --- cmd/flowrunner/runner_test.go | 14 ++++++---- .../testdata/flows/all_actions_test.json | 28 ++++++------------- .../testdata/flows/subflow_test.json | 8 +++--- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/cmd/flowrunner/runner_test.go b/cmd/flowrunner/runner_test.go index a3319184a..be6f579a1 100644 --- a/cmd/flowrunner/runner_test.go +++ b/cmd/flowrunner/runner_test.go @@ -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() @@ -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) diff --git a/cmd/flowrunner/testdata/flows/all_actions_test.json b/cmd/flowrunner/testdata/flows/all_actions_test.json index 834791929..4573ec59b 100644 --- a/cmd/flowrunner/testdata/flows/all_actions_test.json +++ b/cmd/flowrunner/testdata/flows/all_actions_test.json @@ -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", @@ -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", @@ -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\" }" } ] } diff --git a/cmd/flowrunner/testdata/flows/subflow_test.json b/cmd/flowrunner/testdata/flows/subflow_test.json index 1ffe37ce1..39bc31072 100644 --- a/cmd/flowrunner/testdata/flows/subflow_test.json +++ b/cmd/flowrunner/testdata/flows/subflow_test.json @@ -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", @@ -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", @@ -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", @@ -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",