-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
47 lines (35 loc) · 980 Bytes
/
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
package main
import (
"bytes"
"net/http/httptest"
"os"
"strings"
"testing"
"github.com/julienschmidt/httprouter"
)
func TestHello(t *testing.T) {
os.Clearenv()
r := httptest.NewRequest("GET", "/hello/sd", bytes.NewReader([]byte{}))
w := httptest.NewRecorder()
var p httprouter.Params = []httprouter.Param{
{Key: "name", Value: "name_value"},
}
Hello(w, r, p)
wanted := `ABLY_API_KEY unset. This must be set from an .env file`
if strings.TrimSpace(w.Body.String()) != wanted {
t.Errorf(`wanted body "%v" got "%v"`, wanted, w.Body.String())
}
}
func TestIndex(t *testing.T) {
r := httptest.NewRequest("GET", "/", bytes.NewReader([]byte{}))
w := httptest.NewRecorder()
var p []httprouter.Param
Index(w, r, p)
if w.Code != 200 {
t.Errorf("wanted response code 200, got %v, body: %s", w.Code, w.Body)
}
wanted := `Welcome!`
if strings.TrimSpace(w.Body.String()) != wanted {
t.Errorf(`wanted body "%v" got "%v"`, wanted, w.Body.String())
}
}