-
Notifications
You must be signed in to change notification settings - Fork 0
/
soma_test.go
51 lines (44 loc) · 977 Bytes
/
soma_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
51
package main
import (
"io"
"net/http/httptest"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSoma(t *testing.T) {
assert := assert.New(t)
assert.Equal(1., sub(2, 1))
}
func TestSomaHandler_Ok(t *testing.T) {
req := httptest.NewRequest(
"GET",
"http://test.com/soma/1/2",
nil)
w := httptest.NewRecorder()
somaHandler(w, req)
resp := w.Result()
body, _ := io.ReadAll(resp.Body)
result, _ := strconv.ParseFloat(string(body), 64)
assert.Equal(t, 3., result)
}
func TestSomaHandler_Error2Param(t *testing.T) {
req := httptest.NewRequest(
"GET",
"http://test.com/soma/1/4d",
nil)
w := httptest.NewRecorder()
somaHandler(w, req)
resp := w.Result()
assert.Equal(t, 400, resp.StatusCode)
}
func TestSomaHandler_Error1Param(t *testing.T) {
req := httptest.NewRequest(
"GET",
"http://test.com/soma/4d/1",
nil)
w := httptest.NewRecorder()
somaHandler(w, req)
resp := w.Result()
assert.Equal(t, 400, resp.StatusCode)
}