forked from goadesign/gorma
/
ui.go
45 lines (40 loc) · 1.18 KB
/
ui.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
package test
import (
"bytes"
"fmt"
"github.com/goadesign/goa"
"github.com/goadesign/goa/goatest"
"github.com/goadesign/gorma/example/app"
"golang.org/x/net/context"
"net/http"
"net/http/httptest"
"testing"
)
// BootstrapUIOK test setup
func BootstrapUIOK(t *testing.T, ctrl app.UIController) {
BootstrapUIOKCtx(t, context.Background(), ctrl)
}
// BootstrapUIOKCtx test setup
func BootstrapUIOKCtx(t *testing.T, ctx context.Context, ctrl app.UIController) {
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("GET", fmt.Sprintf("/"), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "UITest"), rw, req, nil)
bootstrapCtx, err := app.NewBootstrapUIContext(goaCtx, service)
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.Bootstrap(bootstrapCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
if rw.Code != 200 {
t.Errorf("invalid response status code: got %+v, expected 200", rw.Code)
}
}