operation_pack_test.go

 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
17	jsonBytes, err := opp.Serialize()
18
19	if err != nil {
20		t.Fatal(err)
21	}
22
23	if len(jsonBytes) == 0 {
24		t.Fatal("empty json")
25	}
26
27	fmt.Println(prettyPrintJSON(jsonBytes))
28}
29
30func prettyPrintJSON(jsonBytes []byte) (string, error) {
31	var prettyBytes bytes.Buffer
32	err := json.Indent(&prettyBytes, jsonBytes, "", "  ")
33	if err != nil {
34		return "", err
35	}
36	return prettyBytes.String(), nil
37}