From c5b70d8d94bda20fb8834782ccdb1dbdfb85b052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Tue, 15 Mar 2022 22:01:10 +0100 Subject: [PATCH] bug: don't serialize multiple time the author, only once in OperationPack --- bug/op_add_comment_test.go | 10 ++++------ bug/op_create_test.go | 3 +-- bug/op_edit_comment_test.go | 3 +-- bug/op_label_change_test.go | 3 +-- bug/op_noop_test.go | 3 +-- bug/op_set_metadata_test.go | 3 +-- bug/op_set_status_test.go | 3 +-- bug/op_set_title_test.go | 3 +-- bug/operation.go | 10 +--------- 9 files changed, 12 insertions(+), 29 deletions(-) diff --git a/bug/op_add_comment_test.go b/bug/op_add_comment_test.go index fb6fa8ed9e1038aa222e529c204582735ea25250..446bdb188088e8d4f10a1a60557912a046a406be 100644 --- a/bug/op_add_comment_test.go +++ b/bug/op_add_comment_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/MichaelMure/git-bug/identity" @@ -22,18 +21,17 @@ func TestAddCommentSerialize(t *testing.T) { before := NewAddCommentOp(rene, unix, "message", nil) data, err := json.Marshal(before) - assert.NoError(t, err) + require.NoError(t, err) var after AddCommentOperation err = json.Unmarshal(data, &after) - assert.NoError(t, err) + require.NoError(t, err) // enforce creating the ID before.Id() - // Replace the identity stub with the real thing - assert.Equal(t, rene.Id(), after.Author().Id()) + // Replace the identity as it's not serialized after.Author_ = rene - assert.Equal(t, before, &after) + require.Equal(t, before, &after) } diff --git a/bug/op_create_test.go b/bug/op_create_test.go index 25b87cfe24950a998fa807b767e9cd4ecbf4ce42..7696d065620251f1b977dfd3cbe65f51dbee2907 100644 --- a/bug/op_create_test.go +++ b/bug/op_create_test.go @@ -76,8 +76,7 @@ func TestCreateSerialize(t *testing.T) { // enforce creating the ID before.Id() - // Replace the identity stub with the real thing - require.Equal(t, rene.Id(), after.Author().Id()) + // Replace the identity as it's not serialized after.Author_ = rene require.Equal(t, before, &after) diff --git a/bug/op_edit_comment_test.go b/bug/op_edit_comment_test.go index 5ba947065a5648f1d2048c3ddeb734a86c9c18f2..62034a0b8d446e9f090557baef8d5052e74c65d3 100644 --- a/bug/op_edit_comment_test.go +++ b/bug/op_edit_comment_test.go @@ -93,8 +93,7 @@ func TestEditCommentSerialize(t *testing.T) { // enforce creating the ID before.Id() - // Replace the identity stub with the real thing - require.Equal(t, rene.Id(), after.Author().Id()) + // Replace the identity as it's not serialized after.Author_ = rene require.Equal(t, before, &after) diff --git a/bug/op_label_change_test.go b/bug/op_label_change_test.go index 40dc4f0dcd28eaba2948f02ba21d4a745b267066..1892724e0eda945949549177f3a303f51a91992d 100644 --- a/bug/op_label_change_test.go +++ b/bug/op_label_change_test.go @@ -30,8 +30,7 @@ func TestLabelChangeSerialize(t *testing.T) { // enforce creating the ID before.Id() - // Replace the identity stub with the real thing - require.Equal(t, rene.Id(), after.Author().Id()) + // Replace the identity as it's not serialized after.Author_ = rene require.Equal(t, before, &after) diff --git a/bug/op_noop_test.go b/bug/op_noop_test.go index 0e3727c2c125d440ee40dfbf78152eeec98d4559..2bbfa219868787dd0313fd5d09ec61cab9729bce 100644 --- a/bug/op_noop_test.go +++ b/bug/op_noop_test.go @@ -32,8 +32,7 @@ func TestNoopSerialize(t *testing.T) { // enforce creating the ID before.Id() - // Replace the identity stub with the real thing - assert.Equal(t, rene.Id(), after.Author().Id()) + // Replace the identity as it's not serialized after.Author_ = rene assert.Equal(t, before, &after) diff --git a/bug/op_set_metadata_test.go b/bug/op_set_metadata_test.go index 78f7d883a5698bf119184864bfe83abb192184a9..62c1c942cc61745db07e064910d9a2e1079969ed 100644 --- a/bug/op_set_metadata_test.go +++ b/bug/op_set_metadata_test.go @@ -119,8 +119,7 @@ func TestSetMetadataSerialize(t *testing.T) { // enforce creating the ID before.Id() - // Replace the identity stub with the real thing - require.Equal(t, rene.Id(), after.Author().Id()) + // Replace the identity as it's not serialized after.Author_ = rene require.Equal(t, before, &after) diff --git a/bug/op_set_status_test.go b/bug/op_set_status_test.go index 83ff22aef648e2bd6c78fc39ed2204d4340e41af..75cadae2d8440f6bb3e505144903240d8f51d84a 100644 --- a/bug/op_set_status_test.go +++ b/bug/op_set_status_test.go @@ -30,8 +30,7 @@ func TestSetStatusSerialize(t *testing.T) { // enforce creating the ID before.Id() - // Replace the identity stub with the real thing - require.Equal(t, rene.Id(), after.Author().Id()) + // Replace the identity as it's not serialized after.Author_ = rene require.Equal(t, before, &after) diff --git a/bug/op_set_title_test.go b/bug/op_set_title_test.go index 7059c4c7a99f2eb02f1a627155c4fbe5ec6bca56..2a2277093d5e387b073b22deee7f37da48bf5ed1 100644 --- a/bug/op_set_title_test.go +++ b/bug/op_set_title_test.go @@ -30,8 +30,7 @@ func TestSetTitleSerialize(t *testing.T) { // enforce creating the ID before.Id() - // Replace the identity stub with the real thing - require.Equal(t, rene.Id(), after.Author().Id()) + // Replace the identity as it's not serialized after.Author_ = rene require.Equal(t, before, &after) diff --git a/bug/operation.go b/bug/operation.go index 2e86921a63db6fc27e53414df33ca6ca717296cd..b5c6b1de330806852d689991f30f882c41076b51 100644 --- a/bug/operation.go +++ b/bug/operation.go @@ -135,7 +135,7 @@ func operationUnmarshaller(author identity.Interface, raw json.RawMessage, resol // OpBase implement the common code for all operations type OpBase struct { OperationType OperationType `json:"type"` - Author_ identity.Interface `json:"author"` + Author_ identity.Interface `json:"-"` // not serialized // TODO: part of the data model upgrade, this should eventually be a timestamp + lamport UnixTime int64 `json:"timestamp"` Metadata map[string]string `json:"metadata,omitempty"` @@ -178,7 +178,6 @@ func (base *OpBase) UnmarshalJSON(data []byte) error { aux := struct { OperationType OperationType `json:"type"` - Author json.RawMessage `json:"author"` UnixTime int64 `json:"timestamp"` Metadata map[string]string `json:"metadata,omitempty"` Nonce []byte `json:"nonce"` @@ -188,14 +187,7 @@ func (base *OpBase) UnmarshalJSON(data []byte) error { return err } - // delegate the decoding of the identity - author, err := identity.UnmarshalJSON(aux.Author) - if err != nil { - return err - } - base.OperationType = aux.OperationType - base.Author_ = author base.UnixTime = aux.UnixTime base.Metadata = aux.Metadata base.Nonce = aux.Nonce