Skip to content

Commit

Permalink
Merge pull request nukosuke#206 from frairon/fix-collaborateurs-marsh…
Browse files Browse the repository at this point in the history
…alling

Bugfix json-marshal collaborators in Ticket
  • Loading branch information
nukosuke authored Aug 2, 2021
2 parents 0dfede2 + cfe8dfc commit 0cf5061
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion zendesk/collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *Collaborators) Append(i interface{}) error {
}

// MarshalJSON is marshaller for Collaborators
func (c *Collaborators) MarshalJSON() ([]byte, error) {
func (c Collaborators) MarshalJSON() ([]byte, error) {
return json.Marshal(c.collaborators)
}

Expand Down
17 changes: 17 additions & 0 deletions zendesk/collaborators_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package zendesk

import (
"encoding/json"
"reflect"
"testing"
)
Expand Down Expand Up @@ -47,3 +48,19 @@ func TestCanBeMarshalled(t *testing.T) {
t.Fatalf("Json output %s did not match expected output %s", out, collaboratorListJSON)
}
}

func TestCanBeRemarshalled(t *testing.T) {
var src, dst Collaborators
marshalled, err := json.Marshal(src)
if err != nil {
t.Fatalf("Marshalling returned an error %v", err)
}
err = json.Unmarshal(marshalled, &dst)
if err != nil {
t.Fatalf("Unmarshal returned an error %v", err)
}

if !reflect.DeepEqual(src, dst) {
t.Fatalf("remarshalling is inconsistent")
}
}
19 changes: 19 additions & 0 deletions zendesk/ticket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,22 @@ func TestDeleteTicket(t *testing.T) {
t.Fatalf("Failed to delete ticket field: %s", err)
}
}

func TestTicketMarshalling(t *testing.T) {
var src, dst Ticket

marshalled, err := json.Marshal(src)
if err != nil {
t.Fatalf("Failed to json-marshal ticket: %v", err)
}

err = json.Unmarshal(marshalled, &dst)
if err != nil {
t.Fatalf("Failed to json-unmarshal ticket: %v", err)
}

if !reflect.DeepEqual(src, dst) {
t.Fatalf("remarshalling is inconsistent")
}

}

0 comments on commit 0cf5061

Please sign in to comment.