-
Notifications
You must be signed in to change notification settings - Fork 4
/
bsDateServer_test.go
48 lines (40 loc) · 1.44 KB
/
bsDateServer_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
package main
import (
"fmt"
"github.com/cucumber/godog"
"io/ioutil"
"net/http"
"strings"
)
var host = "http://localhost:10000"
var res *http.Response
func aRequestIsSentToTheEndpoint(method, endpoint string) error {
var reader = strings.NewReader("")
var request, err = http.NewRequest(method, host+endpoint, reader)
if err != nil {
return fmt.Errorf("could not create request %s", err.Error())
}
res, err = http.DefaultClient.Do(request)
if err != nil {
return fmt.Errorf("could not send request %s", err.Error())
}
return nil
}
func theHTTPresponseCodeShouldBe(expectedCode int) error {
if expectedCode != res.StatusCode {
return fmt.Errorf("status code not as expected! Expected '%d', got '%d'", expectedCode, res.StatusCode)
}
return nil
}
func theResponseContentShouldBe(expectedContent string) error {
body, _ := ioutil.ReadAll(res.Body)
if expectedContent != strings.TrimSpace(string(body)) {
return fmt.Errorf("response content not as expected! Expected '%s', got '%s'", expectedContent, string(body))
}
return nil
}
func FeatureContext(ctx *godog.ScenarioContext) {
ctx.Step(`^a "([^"]*)" request is sent to the endpoint "([^"]*)"$`, aRequestIsSentToTheEndpoint)
ctx.Step(`^the HTTP-response code should be "(\d+)"$`, theHTTPresponseCodeShouldBe)
ctx.Step(`^the response content should be "([^"]*)"$`, theResponseContentShouldBe)
}