-
Notifications
You must be signed in to change notification settings - Fork 2
/
convert_test.go
60 lines (43 loc) · 1.28 KB
/
convert_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
52
53
54
55
56
57
58
59
60
package jitter
import (
"bufio"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestConvertMemHandlerNoParticipant(t *testing.T) {
req, err := http.NewRequest("GET", "", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
http.HandlerFunc(ConvertMemHandler).ServeHTTP(rr, req)
status := rr.Code
assert.Equal(t, http.StatusInternalServerError, status)
}
func TestConvertMemHandlerWithParticipant(t *testing.T) {
file, err := os.Open("res/data/FESB70821B.MEM")
assert.NoError(t, err)
req, err := http.NewRequest("GET", "", bufio.NewReader(file))
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
http.HandlerFunc(ConvertMemHandler).ServeHTTP(rr, req)
assert.Equal(t, http.StatusOK, rr.Code)
// Just make sure something somewhat long is being printed. Great test, isn't it?
assert.True(t, len(rr.Body.String()) > 100)
}
func TestConvertMemHandlerWithInvalidParticipant(t *testing.T) {
file, err := os.Open("res/data/participants.json")
assert.NoError(t, err)
req, err := http.NewRequest("GET", "", bufio.NewReader(file))
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
http.HandlerFunc(ConvertMemHandler).ServeHTTP(rr, req)
assert.Equal(t, http.StatusInternalServerError, rr.Code)
}