/
main_test.go
50 lines (40 loc) · 1.08 KB
/
main_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
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
func performRequest(r http.Handler, method, path string, body io.Reader) *httptest.ResponseRecorder {
req, _ := http.NewRequest(method, path, body)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
return w
}
func TestReadiness(t *testing.T) {
router := SetupRouter()
response := performRequest(router, "GET", "/", nil)
assert.Equal(t, http.StatusOK, response.Code)
assert.Equal(t, "ok", response.Body.String())
}
func TestGeneratingCases(t *testing.T) {
requestBodyStruct := gin.H{
"factors": "SomeFactor: 1234567,2,3,4",
}
requestBody, _ := json.Marshal(requestBodyStruct)
router := SetupRouter()
response := performRequest(
router,
"POST",
"/generate_cases",
bytes.NewReader(requestBody))
assert.Equal(t, http.StatusOK, response.Code)
responseBody := response.Body.String()
assert.True(t, strings.Contains(responseBody, "SomeFactor"))
assert.True(t, strings.Contains(responseBody, "1234567"))
}