1package tests
2
3import (
4 "bytes"
5 "encoding/json"
6 "fmt"
7 "github.com/MichaelMure/git-bug/bug"
8 "testing"
9)
10
11func TestOperationPackSerialize(t *testing.T) {
12 opp := bug.OperationPack{}
13
14 opp.Append(createOp)
15 opp.Append(setTitleOp)
16 opp.Append(addCommentOp)
17
18 jsonBytes, err := opp.Serialize()
19
20 if err != nil {
21 t.Fatal(err)
22 }
23
24 if len(jsonBytes) == 0 {
25 t.Fatal("empty json")
26 }
27
28 fmt.Println(prettyPrintJSON(jsonBytes))
29}
30
31func prettyPrintJSON(jsonBytes []byte) (string, error) {
32 var prettyBytes bytes.Buffer
33 err := json.Indent(&prettyBytes, jsonBytes, "", " ")
34 if err != nil {
35 return "", err
36 }
37 return prettyBytes.String(), nil
38}