-
Notifications
You must be signed in to change notification settings - Fork 2
/
outliers_test.go
66 lines (48 loc) · 1.47 KB
/
outliers_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
61
62
63
64
65
66
package jitter
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"gogs.bellstone.ca/james/jitter/lib/data"
)
func TestOutliersHandlerNoParticipant(t *testing.T) {
req, err := http.NewRequest("GET", "", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
http.HandlerFunc(OutlierScoreHandler).ServeHTTP(rr, req)
status := rr.Code
assert.Equal(t, http.StatusInternalServerError, status)
}
func TestOutliersHandlerWithParticipantName(t *testing.T) {
req, err := http.NewRequest("GET", "?name=CA-CR21S", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
http.HandlerFunc(OutlierScoreHandler).ServeHTTP(rr, req)
status := rr.Code
assert.Equal(t, http.StatusOK, status)
// Just make sure something somewhat long is being printed. Great test, isn't it?
assert.True(t, len(rr.Body.String()) > 100)
}
func TestConvertMemHandlerWithParticipantData(t *testing.T) {
mefData, err := data.AsMef()
assert.NoError(t, err)
memData := mefData.MemWithKey("CA-CR21S")
jsMem, err := json.Marshal(memData)
assert.NoError(t, err)
req, err := http.NewRequest("GET", "", bytes.NewReader(jsMem))
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
http.HandlerFunc(OutlierScoreHandler).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)
}