forked from bp-alex/ibconnect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil_test.go
More file actions
51 lines (41 loc) · 1.25 KB
/
util_test.go
File metadata and controls
51 lines (41 loc) · 1.25 KB
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
48
49
50
51
package server
import (
"fmt"
"github.com/ant0ine/go-json-rest/rest/test"
"github.com/benalexau/ibconnect/core"
"github.com/benalexau/ibconnect/gateway"
"net/http"
"testing"
"time"
)
func TestUuid(t *testing.T) {
u := Util{}
uuid := u.uuid()
if len(uuid) != 36 {
t.Fatalf("unexpected length of UUID %s", uuid)
}
}
func TestErrorHandlerInternalServerError(t *testing.T) {
c := core.NewTestConfig(t)
ctx, err := core.NewContext(c)
if err != nil {
t.Fatal(err)
}
defer ctx.Close()
handler := Handler(true, ctx.DB, ctx.N)
var ff gateway.FeedFactory = &gateway.AccountFeedFactory{AccountRefresh: c.AccountRefresh}
WaitForFeed(t, ctx, &ff, 5*time.Second)
ctx.DB.Close() // this will cause an internal server error
recorded := test.RunRequest(t, handler, test.MakeSimpleRequest("GET", "http://1.2.3.4/v1/accounts", nil))
recorded.CodeIs(http.StatusInternalServerError)
recorded.ContentTypeIsJson()
}
func TestErrorHandlerDataNotFound(t *testing.T) {
ctx, handler := NewTestHandler(t)
defer ctx.Close()
accountCode := "neverfind"
url := fmt.Sprintf("http://1.2.3.4/v1/accounts/%s", accountCode)
recorded := test.RunRequest(t, handler, test.MakeSimpleRequest("GET", url, nil))
recorded.CodeIs(http.StatusNotFound)
recorded.ContentTypeIsJson()
}