-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
46 lines (38 loc) · 1.08 KB
/
integration_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
package main
import (
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestServe(t *testing.T) {
storage := NewInMemory()
service := NewFizzBuzzService(storage)
controller := NewController(service)
router := NewGinRouter(controller)
go func() {
assert.NoError(t, router.Serve(":9000"))
}()
check := func() bool {
if err := router.Serve(":9000"); err != nil {
return true
}
return false
}
checkTimout := 500 * time.Millisecond
checkPeriod := 2 * time.Millisecond
assert.Eventually(t, check, checkTimout, checkPeriod)
client := &http.Client{}
resp1, err := client.Get("http://localhost:9000/fizz-buzz/stats")
assert.NoError(t, err)
defer resp1.Body.Close()
assert.Equal(t, resp1.StatusCode, http.StatusOK)
resp2, err := client.Get("http://localhost:9000/fizz-buzz/")
assert.NoError(t, err)
defer resp2.Body.Close()
assert.Equal(t, resp2.StatusCode, http.StatusBadRequest)
resp3, err := client.Get("http://localhost:9000/not-found/")
assert.NoError(t, err)
defer resp3.Body.Close()
assert.Equal(t, resp3.StatusCode, http.StatusNotFound)
}