aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-13 21:21:24 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-13 21:21:24 +0200
commit1779a0f3b92d58654b43444addeaf437a64d77a8 (patch)
tree9f973413454894f0456d7379425070d468712242 /tests
parent289f8d53ee960d35c1f0c42e8753ad536737b875 (diff)
downloadgit-bug-1779a0f3b92d58654b43444addeaf437a64d77a8.tar.gz
serialize a Bug to git as a blob+tree+commit+ref
Diffstat (limited to 'tests')
-rw-r--r--tests/bug_test.go2
-rw-r--r--tests/operation_iterator_test.go6
-rw-r--r--tests/operation_pack_test.go37
3 files changed, 42 insertions, 3 deletions
diff --git a/tests/bug_test.go b/tests/bug_test.go
index dfb3ac09..ab7803f9 100644
--- a/tests/bug_test.go
+++ b/tests/bug_test.go
@@ -38,7 +38,7 @@ func TestBugValidity(t *testing.T) {
t.Fatal("Bug with multiple CREATE should be invalid")
}
- bug1.Commit()
+ bug1.Commit(mockRepo)
if bug1.IsValid() {
t.Fatal("Bug with multiple CREATE should be invalid")
diff --git a/tests/operation_iterator_test.go b/tests/operation_iterator_test.go
index e41fff99..b2f01513 100644
--- a/tests/operation_iterator_test.go
+++ b/tests/operation_iterator_test.go
@@ -3,6 +3,7 @@ package tests
import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/bug/operations"
+ "github.com/MichaelMure/git-bug/repository"
"testing"
)
@@ -14,6 +15,7 @@ var (
createOp = operations.NewCreateOp(rene, "title", "message")
setTitleOp = operations.NewSetTitleOp("title2")
+ mockRepo = repository.NewMockRepoForTest()
)
func TestOpIterator(t *testing.T) {
@@ -26,12 +28,12 @@ func TestOpIterator(t *testing.T) {
bug1.Append(createOp)
bug1.Append(setTitleOp)
- bug1.Commit()
+ bug1.Commit(mockRepo)
bug1.Append(setTitleOp)
bug1.Append(setTitleOp)
bug1.Append(setTitleOp)
- bug1.Commit()
+ bug1.Commit(mockRepo)
bug1.Append(setTitleOp)
bug1.Append(setTitleOp)
diff --git a/tests/operation_pack_test.go b/tests/operation_pack_test.go
new file mode 100644
index 00000000..8ca43c09
--- /dev/null
+++ b/tests/operation_pack_test.go
@@ -0,0 +1,37 @@
+package tests
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "github.com/MichaelMure/git-bug/bug"
+ "testing"
+)
+
+func TestOperationPackSerialize(t *testing.T) {
+ opp := bug.OperationPack{}
+
+ opp.Append(createOp)
+ opp.Append(setTitleOp)
+
+ jsonBytes, err := opp.Serialize()
+
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if len(jsonBytes) == 0 {
+ t.Fatal("empty json")
+ }
+
+ fmt.Println(prettyPrintJSON(jsonBytes))
+}
+
+func prettyPrintJSON(jsonBytes []byte) (string, error) {
+ var prettyBytes bytes.Buffer
+ err := json.Indent(&prettyBytes, jsonBytes, "", " ")
+ if err != nil {
+ return "", err
+ }
+ return prettyBytes.String(), nil
+}