aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-14 22:17:37 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-14 22:17:37 +0200
commitda470993d13ce63087034db9b7e8ffbdf18e87a5 (patch)
tree7846ad86de6d93c51c54bf3e764a2108baa63612 /tests
parentf8e07748743f7e66ff1adf101a797cb1bedfc140 (diff)
downloadgit-bug-da470993d13ce63087034db9b7e8ffbdf18e87a5.tar.gz
complete the storage/read process + tests (!)
Diffstat (limited to 'tests')
-rw-r--r--tests/bug_test.go29
-rw-r--r--tests/operation_pack_test.go18
2 files changed, 33 insertions, 14 deletions
diff --git a/tests/bug_test.go b/tests/bug_test.go
index ab7803f9..2fb79be5 100644
--- a/tests/bug_test.go
+++ b/tests/bug_test.go
@@ -2,6 +2,8 @@ package tests
import (
"github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/repository"
+ "reflect"
"testing"
)
@@ -11,7 +13,7 @@ func TestBugId(t *testing.T) {
t.Error(err)
}
- if len(bug1.HumanId()) == 0 {
+ if len(bug1.Id()) == 0 {
t.Fatal("Bug doesn't have a human readable identifier")
}
}
@@ -44,3 +46,28 @@ func TestBugValidity(t *testing.T) {
t.Fatal("Bug with multiple CREATE should be invalid")
}
}
+
+func TestBugSerialisation(t *testing.T) {
+ bug1, err := bug.NewBug()
+ if err != nil {
+ t.Error(err)
+ }
+
+ bug1.Append(createOp)
+ bug1.Append(setTitleOp)
+ bug1.Append(setTitleOp)
+ bug1.Append(addCommentOp)
+
+ repo := repository.NewMockRepoForTest()
+
+ bug1.Commit(repo)
+
+ bug2, err := bug.ReadBug(repo, bug1.Id())
+ if err != nil {
+ t.Error(err)
+ }
+
+ if !reflect.DeepEqual(bug1, bug2) {
+ t.Fatalf("%s different than %s", bug1, bug2)
+ }
+}
diff --git a/tests/operation_pack_test.go b/tests/operation_pack_test.go
index 2b19e364..35b77a8f 100644
--- a/tests/operation_pack_test.go
+++ b/tests/operation_pack_test.go
@@ -1,9 +1,6 @@
package tests
import (
- "bytes"
- "encoding/json"
- "fmt"
"github.com/MichaelMure/git-bug/bug"
"testing"
)
@@ -15,24 +12,19 @@ func TestOperationPackSerialize(t *testing.T) {
opp.Append(setTitleOp)
opp.Append(addCommentOp)
- jsonBytes, err := opp.Serialize()
+ data, err := opp.Serialize()
if err != nil {
t.Fatal(err)
}
- if len(jsonBytes) == 0 {
- t.Fatal("empty json")
+ if len(data) == 0 {
+ t.Fatal("empty serialized data")
}
- fmt.Println(prettyPrintJSON(jsonBytes))
-}
+ _, err = bug.ParseOperationPack(data)
-func prettyPrintJSON(jsonBytes []byte) (string, error) {
- var prettyBytes bytes.Buffer
- err := json.Indent(&prettyBytes, jsonBytes, "", " ")
if err != nil {
- return "", err
+ t.Fatal(err)
}
- return prettyBytes.String(), nil
}