From e2aca1c6ded97d856e74bbb7ff66e2c149718f8a Mon Sep 17 00:00:00 2001 From: geauxvirtual Date: Mon, 22 Aug 2016 16:56:55 -0700 Subject: [PATCH] Rename marshalTask and MarshalBody functions to match what they actually do --- core/task.go | 8 ++++---- core/task_test.go | 16 ++++++++-------- mgmt/rest/config.go | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/core/task.go b/core/task.go index 0a07f1a18..c78d684db 100644 --- a/core/task.go +++ b/core/task.go @@ -175,7 +175,7 @@ func CreateTaskFromContent(body io.ReadCloser, startOnCreate bool, opts ...TaskOption) (Task, TaskErrors)) (Task, error) { - tr, err := marshalTask(body) + tr, err := createTaskRequest(body) if err != nil { return nil, err } @@ -221,16 +221,16 @@ func CreateTaskFromContent(body io.ReadCloser, return task, nil } -func marshalTask(body io.ReadCloser) (*TaskCreationRequest, error) { +func createTaskRequest(body io.ReadCloser) (*TaskCreationRequest, error) { var tr TaskCreationRequest - errCode, err := MarshalBody(&tr, body) + errCode, err := UnmarshalBody(&tr, body) if errCode != 0 && err != nil { return nil, err } return &tr, nil } -func MarshalBody(in interface{}, body io.ReadCloser) (int, error) { +func UnmarshalBody(in interface{}, body io.ReadCloser) (int, error) { b, err := ioutil.ReadAll(body) if err != nil { return 500, err diff --git a/core/task_test.go b/core/task_test.go index 0bd721968..ee1fce24e 100644 --- a/core/task_test.go +++ b/core/task_test.go @@ -73,13 +73,13 @@ func okRoutine(sch schedule.Schedule, return nil, nil } -func TestMarshalBodyTask(t *testing.T) { +func TestUnmarshalBodyTask(t *testing.T) { Convey("Non existing file", t, func() { file, err := os.Open(DUMMY_FILE) So(file, ShouldBeNil) So(err.Error(), ShouldEqual, fmt.Sprintf("open %s: no such file or directory", DUMMY_FILE)) - code, err := MarshalBody(nil, file) + code, err := UnmarshalBody(nil, file) So(code, ShouldEqual, 500) So(err, ShouldNotBeNil) So(err.Error(), ShouldEqual, "invalid argument") @@ -90,7 +90,7 @@ func TestMarshalBodyTask(t *testing.T) { file, err := os.Open(YAML_FILE) So(file, ShouldNotBeNil) So(err, ShouldBeNil) - code, err := MarshalBody(&tr, file) + code, err := UnmarshalBody(&tr, file) So(code, ShouldEqual, 400) So(err, ShouldNotBeNil) So(err.Error(), ShouldEqual, "invalid character '-' in numeric literal") @@ -101,19 +101,19 @@ func TestMarshalBodyTask(t *testing.T) { file, err := os.Open(JSON_FILE) So(file, ShouldNotBeNil) So(err, ShouldBeNil) - code, err := MarshalBody(&tr, file) + code, err := UnmarshalBody(&tr, file) So(code, ShouldEqual, 0) So(err, ShouldBeNil) }) } -func TestMarshalTask(t *testing.T) { +func TestCreateTaskRequest(t *testing.T) { Convey("Non existing file", t, func() { file, err := os.Open(DUMMY_FILE) So(file, ShouldBeNil) So(err.Error(), ShouldEqual, fmt.Sprintf("open %s: no such file or directory", DUMMY_FILE)) - task, err := marshalTask(file) + task, err := createTaskRequest(file) So(task, ShouldBeNil) So(err, ShouldNotBeNil) So(err.Error(), ShouldEqual, "invalid argument") @@ -123,7 +123,7 @@ func TestMarshalTask(t *testing.T) { file, err := os.Open(YAML_FILE) So(file, ShouldNotBeNil) So(err, ShouldBeNil) - task, err := marshalTask(file) + task, err := createTaskRequest(file) So(task, ShouldBeNil) So(err, ShouldNotBeNil) So(err.Error(), ShouldEqual, "invalid character '-' in numeric literal") @@ -133,7 +133,7 @@ func TestMarshalTask(t *testing.T) { file, err := os.Open(JSON_FILE) So(file, ShouldNotBeNil) So(err, ShouldBeNil) - task, err := marshalTask(file) + task, err := createTaskRequest(file) So(err, ShouldBeNil) So(task, ShouldNotBeNil) So(task.Name, ShouldEqual, "") diff --git a/mgmt/rest/config.go b/mgmt/rest/config.go index 40c1062ec..9085a5f17 100644 --- a/mgmt/rest/config.go +++ b/mgmt/rest/config.go @@ -87,7 +87,7 @@ func (s *Server) deletePluginConfigItem(w http.ResponseWriter, r *http.Request, } src := []string{} - errCode, err := core.MarshalBody(&src, r.Body) + errCode, err := core.UnmarshalBody(&src, r.Body) if errCode != 0 && err != nil { respond(400, rbody.FromError(err), w) return @@ -129,7 +129,7 @@ func (s *Server) setPluginConfigItem(w http.ResponseWriter, r *http.Request, p h } src := cdata.NewNode() - errCode, err := core.MarshalBody(src, r.Body) + errCode, err := core.UnmarshalBody(src, r.Body) if errCode != 0 && err != nil { respond(400, rbody.FromError(err), w) return