Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Rename marshalTask and MarshalBody functions to match what they actua…
Browse files Browse the repository at this point in the history
…lly do
  • Loading branch information
geauxvirtual committed Aug 23, 2016
1 parent 4e6b19d commit e2aca1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions core/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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, "")
Expand Down
4 changes: 2 additions & 2 deletions mgmt/rest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e2aca1c

Please sign in to comment.