aboutsummaryrefslogtreecommitdiffstats
path: root/bug/operations
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 /bug/operations
parentf8e07748743f7e66ff1adf101a797cb1bedfc140 (diff)
downloadgit-bug-da470993d13ce63087034db9b7e8ffbdf18e87a5.tar.gz
complete the storage/read process + tests (!)
Diffstat (limited to 'bug/operations')
-rw-r--r--bug/operations/create.go6
-rw-r--r--bug/operations/operation_test.go57
-rw-r--r--bug/operations/operations.go10
3 files changed, 13 insertions, 60 deletions
diff --git a/bug/operations/create.go b/bug/operations/create.go
index 1c34f85d..49b648a2 100644
--- a/bug/operations/create.go
+++ b/bug/operations/create.go
@@ -11,9 +11,9 @@ var _ bug.Operation = CreateOperation{}
type CreateOperation struct {
bug.OpBase
- Title string `json:"t"`
- Message string `json:"m"`
- Author bug.Person `json:"a"`
+ Title string
+ Message string
+ Author bug.Person
}
func NewCreateOp(author bug.Person, title, message string) CreateOperation {
diff --git a/bug/operations/operation_test.go b/bug/operations/operation_test.go
deleted file mode 100644
index e53e524b..00000000
--- a/bug/operations/operation_test.go
+++ /dev/null
@@ -1,57 +0,0 @@
-package operations
-
-import (
- "github.com/MichaelMure/git-bug/bug"
- "testing"
-)
-
-// Different type with the same fields
-type CreateOperation2 struct {
- Title string
- Message string
-}
-
-func (op CreateOperation2) OpType() bug.OperationType {
- return bug.UNKNOW
-}
-
-func (op CreateOperation2) Apply(snapshot bug.Snapshot) bug.Snapshot {
- // no-op
- return snapshot
-}
-
-func TestOperationsEquality(t *testing.T) {
- var rene = bug.Person{
- Name: "René Descartes",
- Email: "rene@descartes.fr",
- }
-
- var A bug.Operation = NewCreateOp(rene, "title", "message")
- var B bug.Operation = NewCreateOp(rene, "title", "message")
- var C bug.Operation = NewCreateOp(rene, "title", "different message")
-
- if A != B {
- t.Fatal("Equal value ops should be tested equals")
- }
-
- if A == C {
- t.Fatal("Different value ops should be tested different")
- }
-
- D := CreateOperation2{Title: "title", Message: "message"}
-
- if A == D {
- t.Fatal("Operations equality should handle the type")
- }
-
- var isaac = bug.Person{
- Name: "Isaac Newton",
- Email: "isaac@newton.uk",
- }
-
- var E bug.Operation = NewCreateOp(isaac, "title", "message")
-
- if A == E {
- t.Fatal("Operation equality should handle the author")
- }
-}
diff --git a/bug/operations/operations.go b/bug/operations/operations.go
new file mode 100644
index 00000000..f42d6e9a
--- /dev/null
+++ b/bug/operations/operations.go
@@ -0,0 +1,10 @@
+package operations
+
+import "encoding/gob"
+
+// Package initialisation used to register operation's type for (de)serialization
+func init() {
+ gob.Register(AddCommentOperation{})
+ gob.Register(CreateOperation{})
+ gob.Register(SetTitleOperation{})
+}