-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub_test.go
50 lines (43 loc) · 948 Bytes
/
sub_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 (
"io"
"net/http/httptest"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSub_OK(t *testing.T) {
assert.Equal(t, 1., sub(2, 1))
}
func TestSubHandler_OK(t *testing.T) {
req := httptest.NewRequest(
"GET",
"http://test.com/sub/2/1",
nil)
w := httptest.NewRecorder()
subHandler(w, req)
resp := w.Result()
body, _ := io.ReadAll(resp.Body)
result, _ := strconv.ParseFloat(string(body), 64)
assert.Equal(t, 1., result)
}
func TestSubHandler_Error2Param(t *testing.T) {
req := httptest.NewRequest(
"GET",
"http://test.com/sub/1/4d",
nil)
w := httptest.NewRecorder()
subHandler(w, req)
resp := w.Result()
assert.Equal(t, 400, resp.StatusCode)
}
func TestSubHandler_Error1Param(t *testing.T) {
req := httptest.NewRequest(
"GET",
"http://test.com/sub/4d/1",
nil)
w := httptest.NewRecorder()
subHandler(w, req)
resp := w.Result()
assert.Equal(t, 400, resp.StatusCode)
}