diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-28 20:39:39 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-29 00:51:54 +0200 |
commit | 1bf268cebc84a9de1e538cbb54bcc0f434022192 (patch) | |
tree | daeb92cd6b15d56a7a7102f95b73756e5b9597d0 /bug/operation_pack_test.go | |
parent | 8af6f7d98f2fd98f85d6a17bcda49983c272cf48 (diff) | |
download | git-bug-1bf268cebc84a9de1e538cbb54bcc0f434022192.tar.gz |
merge package operations into bug, they are tightly coupled anyway
Diffstat (limited to 'bug/operation_pack_test.go')
-rw-r--r-- | bug/operation_pack_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/bug/operation_pack_test.go b/bug/operation_pack_test.go new file mode 100644 index 00000000..48f9f80c --- /dev/null +++ b/bug/operation_pack_test.go @@ -0,0 +1,53 @@ +package bug + +import ( + "encoding/json" + "testing" + + "github.com/MichaelMure/git-bug/util/git" + "github.com/go-test/deep" +) + +func TestOperationPackSerialize(t *testing.T) { + opp := &OperationPack{} + + opp.Append(createOp) + opp.Append(setTitleOp) + opp.Append(addCommentOp) + opp.Append(setStatusOp) + opp.Append(labelChangeOp) + + opMeta := NewCreateOp(rene, unix, "title", "message", nil) + opMeta.SetMetadata("key", "value") + opp.Append(opMeta) + + if len(opMeta.Metadata) != 1 { + t.Fatal() + } + + opFile := NewCreateOp(rene, unix, "title", "message", []git.Hash{ + "abcdef", + "ghijkl", + }) + opp.Append(opFile) + + if len(opFile.Files) != 2 { + t.Fatal() + } + + data, err := json.Marshal(opp) + if err != nil { + t.Fatal(err) + } + + var opp2 *OperationPack + err = json.Unmarshal(data, &opp2) + if err != nil { + t.Fatal(err) + } + + deep.CompareUnexportedFields = false + if diff := deep.Equal(opp, opp2); diff != nil { + t.Fatal(diff) + } +} |