forked from convox/rack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
service_test.go
51 lines (38 loc) · 1.17 KB
/
service_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
47
48
49
50
51
package client
import (
"net/url"
"testing"
"github.com/convox/rack/test"
"github.com/stretchr/testify/assert"
)
func TestGetService(t *testing.T) {
ts := testServer(t,
test.Http{Method: "GET", Path: "/services/convox-events", Code: 200, Response: Resource{
Name: "convox-events",
Status: "running",
Type: "type",
},
},
)
defer ts.Close()
service, err := testClient(t, ts.URL).GetResource("convox-events")
assert.NotNil(t, service, "service should not be nil")
assert.NoError(t, err)
assert.Equal(t, "convox-events", service.Name, ".Name should be convox-events")
assert.Equal(t, "running", service.Status, ".Status should be running")
assert.Equal(t, "type", service.Type, ".Type should be type")
}
func TestGetServiceFailure(t *testing.T) {
ts := testServer(t,
test.Http{Method: "GET", Path: "/services/nonexistent", Code: 503, Response: Error{
Error: "invalid resource",
}},
)
defer ts.Close()
u, _ := url.Parse(ts.URL)
client := New(u.Host, "test", "test")
service, err := client.GetResource("nonexistent")
assert.Nil(t, service)
assert.NotNil(t, err)
assert.Equal(t, "invalid resource", err.Error(), "err should be invalid resource")
}