-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_test.go
36 lines (31 loc) · 1.03 KB
/
route_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
package gorest
import (
"reflect"
"testing"
)
// TestRouteGetPattern verifies the Route GetPattern behaviour.
func TestRouteGetPattern(t *testing.T) {
r := NewRoute(nil, "/the/pattern")
if r.GetPattern() != "/the/pattern" {
t.Fatalf("Unexpected patter found. Expected: %s - Found: %s.", "/the/pattern", r.GetPattern())
}
}
// TestRouteGetResource verifies the Route GetResource behaviour.
func TestRouteGetResource(t *testing.T) {
type testResource struct {
A string
}
resource := testResource{"a_value"}
r := NewRoute(resource, "")
got := r.GetResource()
if reflect.TypeOf(got) != reflect.TypeOf(resource) {
t.Fatalf("Unexpected resource type found. Expected: %s - Found: %s.", reflect.TypeOf(resource), reflect.TypeOf(got))
}
convertedResource, ok := got.(testResource)
if !ok {
t.Fatalf("Failed type conversion to testResource. Type is: %s.", reflect.TypeOf(got).String())
}
if convertedResource.A != "a_value" {
t.Fatalf("Unexpected resource content. Expected: %s - Found: %s.", "a_value", convertedResource.A)
}
}