-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgort_test.go
39 lines (35 loc) · 1023 Bytes
/
gort_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
package gort
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestListScripts(t *testing.T) {
req, err := http.NewRequest("GET", "/v1/list-dist", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handler := http.HandlerFunc(ListScriptsHandler)
handler.ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
expected := "./dist seems like empty"
if rr.Body.String() != expected {
t.Errorf("handler returned unexpected body: got %v want %v",
rr.Body.String(), expected)
}
}
func TestNotFound(t *testing.T) {
req, _ := http.NewRequest("GET", "/any-url", nil)
rr := httptest.NewRecorder()
handler := http.HandlerFunc(NotFoundHandler)
handler.ServeHTTP(rr, req)
expected := "This page does not exist!"
if rr.Body.String() != expected && rr.Code != http.StatusNotFound {
t.Errorf("handler returned unexpected body: got %v want %v",
rr.Body.String(), expected)
}
}