forked from mihaitodor/ringman
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemberlist_test.go
More file actions
77 lines (59 loc) · 2.02 KB
/
Copy pathmemberlist_test.go
File metadata and controls
77 lines (59 loc) · 2.02 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ringman
import (
"io/ioutil"
"net/http/httptest"
"net/url"
"testing"
"github.com/Nitro/memberlist"
. "github.com/smartystreets/goconvey/convey"
)
func Test_NewMemberlistRing(t *testing.T) {
// This must be started out here so we don't re-use the port and
// start the list up each time
mlConfig := memberlist.DefaultLANConfig()
mlConfig.BindPort = 35001
Convey("NewMemberlistRing()", t, func() {
mlistRing, err := NewMemberlistRing(mlConfig, []string{}, "8000", "default")
So(err, ShouldBeNil)
ourAddr := mlistRing.Memberlist.LocalNode().Addr.String()
Convey("returns a properly configured MemberlistRing", func() {
So(mlistRing.Memberlist, ShouldNotBeNil)
So(mlistRing.manager, ShouldNotBeNil)
node, err := mlistRing.manager.GetNode("beowulf")
So(err, ShouldBeNil)
So(node, ShouldEqual, ourAddr+":8000")
So(len(mlistRing.Memberlist.Members()), ShouldEqual, 1)
})
})
}
func Test_MemberListRingShutdown(t *testing.T) {
Convey("NewMemberlistRing()", t, func() {
mlistRing, err := NewDefaultMemberlistRing([]string{}, "8000")
So(err, ShouldBeNil)
mlistRing.Shutdown()
So(mlistRing.manager.Ping(), ShouldBeFalse)
So(mlistRing.manager.cmdChan, ShouldBeNil)
})
}
func Test_HttpGetNodeHandler(t *testing.T) {
Convey("HttpGetNodeHandler()", t, func() {
// Don't initialize it because we don't need it to be
mlistRing := &MemberlistRing{}
req := httptest.NewRequest("GET", "/services/boccacio.json", nil)
recorder := httptest.NewRecorder()
Convey("returns a 404 when no key is provided", func() {
mlistRing.HttpGetNodeHandler(recorder, req)
So(recorder.Result().StatusCode, ShouldEqual, 404)
})
Convey("returns a node when a key is provided", func() {
form := url.Values{}
form.Set("key", "bocaccio")
req.Form = form
mlistRing.HttpGetNodeHandler(recorder, req)
bodyBytes, _ := ioutil.ReadAll(recorder.Result().Body)
body := string(bodyBytes)
So(recorder.Result().StatusCode, ShouldEqual, 200)
So(body, ShouldContainSubstring, `"Key": "bocaccio"`)
})
})
}