-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
37 lines (29 loc) · 883 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
package main
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/matryer/is"
)
func TestMain(t *testing.T) {
is := is.New(t)
srv, err := newServer()
is.NoErr(err) // newServer error
hsrv := httptest.NewServer(srv)
defer hsrv.Close()
req, err := http.NewRequest("get", hsrv.URL+"/", nil)
is.NoErr(err) // NewRequest error
client := &http.Client{
Timeout: 1 * time.Minute,
}
resp, err := client.Do(req)
is.NoErr(err) // Client request error
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
is.NoErr(err) // Body read error
is.True(strings.Contains(string(b), `<h1>Welcome`)) // Contains welcome
is.True(strings.Contains(string(b), `<button type='submit'>Create a bin</button>`)) // Contains button
}