Exemplo n.º 1
0
func TestNodeAddHandler(t *testing.T) {

	var msg requests.NodeInfoResp

	// Instead of coding our own JSON here,
	// create the JSON message as a string to test the handler
	request := []byte(`{
        "name" : "test_name",
        "zone" : 12345
    }`)

	n := NewNodeServer(mock.NewMockPlugin())
	ts := httptest.NewServer(http.HandlerFunc(n.NodeAddHandler))
	defer ts.Close()

	// Request
	r, err := http.Post(ts.URL, "application/json", bytes.NewBuffer(request))
	tests.Assert(t, r.StatusCode == http.StatusCreated)
	tests.Assert(t, err == nil)

	// Check body
	err = utils.GetJsonFromResponse(r, &msg)
	tests.Assert(t, err == nil)

	tests.Assert(t, msg.Name == "test_name")
	tests.Assert(t, msg.Zone == 12345)
}
Exemplo n.º 2
0
func NewPlugin(name string) Plugin {

	switch name {
	case "mock":
		return mock.NewMockPlugin()
	case "glusterfs":
		return glusterfs.NewGlusterFSPlugin()
	default:
		return nil
	}

}
Exemplo n.º 3
0
func TestNodeListHandlerEmpty(t *testing.T) {

	var msg requests.NodeListResponse

	n := NewNodeServer(mock.NewMockPlugin())
	ts := httptest.NewServer(http.HandlerFunc(n.NodeListHandler))
	defer ts.Close()

	// Request
	r, err := http.Get(ts.URL)
	tests.Assert(t, r.StatusCode == http.StatusOK)
	tests.Assert(t, err == nil)

	// Check body
	err = utils.GetJsonFromResponse(r, &msg)
	tests.Assert(t, err == nil)

	tests.Assert(t, len(msg.Nodes) == 0)
}