diff options
author | Michael Muré <batolettre@gmail.com> | 2022-08-24 21:40:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-24 21:40:30 +0200 |
commit | 5c91174a84592b027c1b432a72ebf2974ec0e4c5 (patch) | |
tree | 1306f7f617968e13e6f28eda51417ae8cd2c6c6a /entities | |
parent | ccb71fea57bb17f267f135cb008470615595c5b7 (diff) | |
parent | e1b172aaf0e984791b5af4a64b144339fd4042f6 (diff) | |
download | git-bug-5c91174a84592b027c1b432a72ebf2974ec0e4c5.tar.gz |
Merge pull request #861 from MichaelMure/test-with-unmarshaler
dag: test op serialisation with the unmarshaller, to allow resolving entities
Diffstat (limited to 'entities')
-rw-r--r-- | entities/bug/bug.go | 2 | ||||
-rw-r--r-- | entities/bug/op_add_comment_test.go | 9 | ||||
-rw-r--r-- | entities/bug/op_create_test.go | 8 | ||||
-rw-r--r-- | entities/bug/op_edit_comment_test.go | 9 | ||||
-rw-r--r-- | entities/bug/op_label_change_test.go | 13 | ||||
-rw-r--r-- | entities/bug/op_set_status_test.go | 5 | ||||
-rw-r--r-- | entities/bug/op_set_title_test.go | 5 | ||||
-rw-r--r-- | entities/bug/operation.go | 2 |
8 files changed, 29 insertions, 24 deletions
diff --git a/entities/bug/bug.go b/entities/bug/bug.go index 4ce10c5b..1140c543 100644 --- a/entities/bug/bug.go +++ b/entities/bug/bug.go @@ -23,7 +23,7 @@ const formatVersion = 4 var def = dag.Definition{ Typename: "bug", Namespace: "bugs", - OperationUnmarshaler: operationUnmarshaller, + OperationUnmarshaler: operationUnmarshaler, FormatVersion: formatVersion, } diff --git a/entities/bug/op_add_comment_test.go b/entities/bug/op_add_comment_test.go index 6f29cb01..fee9e785 100644 --- a/entities/bug/op_add_comment_test.go +++ b/entities/bug/op_add_comment_test.go @@ -4,15 +4,16 @@ import ( "testing" "github.com/MichaelMure/git-bug/entities/identity" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/repository" ) func TestAddCommentSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *AddCommentOperation { - return NewAddCommentOp(author, unixTime, "message", nil) + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*AddCommentOperation, entity.Resolvers) { + return NewAddCommentOp(author, unixTime, "message", nil), nil }) - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *AddCommentOperation { - return NewAddCommentOp(author, unixTime, "message", []repository.Hash{"hash1", "hash2"}) + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*AddCommentOperation, entity.Resolvers) { + return NewAddCommentOp(author, unixTime, "message", []repository.Hash{"hash1", "hash2"}), nil }) } diff --git a/entities/bug/op_create_test.go b/entities/bug/op_create_test.go index e534162b..d8bde46f 100644 --- a/entities/bug/op_create_test.go +++ b/entities/bug/op_create_test.go @@ -40,10 +40,10 @@ func TestCreate(t *testing.T) { } func TestCreateSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *CreateOperation { - return NewCreateOp(author, unixTime, "title", "message", nil) + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*CreateOperation, entity.Resolvers) { + return NewCreateOp(author, unixTime, "title", "message", nil), nil }) - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *CreateOperation { - return NewCreateOp(author, unixTime, "title", "message", []repository.Hash{"hash1", "hash2"}) + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*CreateOperation, entity.Resolvers) { + return NewCreateOp(author, unixTime, "title", "message", []repository.Hash{"hash1", "hash2"}), nil }) } diff --git a/entities/bug/op_edit_comment_test.go b/entities/bug/op_edit_comment_test.go index 1b649cd1..2ca1345e 100644 --- a/entities/bug/op_edit_comment_test.go +++ b/entities/bug/op_edit_comment_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/MichaelMure/git-bug/entities/identity" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/repository" ) @@ -75,10 +76,10 @@ func TestEdit(t *testing.T) { } func TestEditCommentSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *EditCommentOperation { - return NewEditCommentOp(author, unixTime, "target", "message", nil) + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*EditCommentOperation, entity.Resolvers) { + return NewEditCommentOp(author, unixTime, "target", "message", nil), nil }) - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *EditCommentOperation { - return NewEditCommentOp(author, unixTime, "target", "message", []repository.Hash{"hash1", "hash2"}) + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*EditCommentOperation, entity.Resolvers) { + return NewEditCommentOp(author, unixTime, "target", "message", []repository.Hash{"hash1", "hash2"}), nil }) } diff --git a/entities/bug/op_label_change_test.go b/entities/bug/op_label_change_test.go index edbe4714..e6dc8803 100644 --- a/entities/bug/op_label_change_test.go +++ b/entities/bug/op_label_change_test.go @@ -4,17 +4,18 @@ import ( "testing" "github.com/MichaelMure/git-bug/entities/identity" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" ) func TestLabelChangeSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *LabelChangeOperation { - return NewLabelChangeOperation(author, unixTime, []Label{"added"}, []Label{"removed"}) + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*LabelChangeOperation, entity.Resolvers) { + return NewLabelChangeOperation(author, unixTime, []Label{"added"}, []Label{"removed"}), nil }) - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *LabelChangeOperation { - return NewLabelChangeOperation(author, unixTime, []Label{"added"}, nil) + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*LabelChangeOperation, entity.Resolvers) { + return NewLabelChangeOperation(author, unixTime, []Label{"added"}, nil), nil }) - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *LabelChangeOperation { - return NewLabelChangeOperation(author, unixTime, nil, []Label{"removed"}) + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*LabelChangeOperation, entity.Resolvers) { + return NewLabelChangeOperation(author, unixTime, nil, []Label{"removed"}), nil }) } diff --git a/entities/bug/op_set_status_test.go b/entities/bug/op_set_status_test.go index 5bb30265..0f6d358a 100644 --- a/entities/bug/op_set_status_test.go +++ b/entities/bug/op_set_status_test.go @@ -5,11 +5,12 @@ import ( "github.com/MichaelMure/git-bug/entities/common" "github.com/MichaelMure/git-bug/entities/identity" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" ) func TestSetStatusSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *SetStatusOperation { - return NewSetStatusOp(author, unixTime, common.ClosedStatus) + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*SetStatusOperation, entity.Resolvers) { + return NewSetStatusOp(author, unixTime, common.ClosedStatus), nil }) } diff --git a/entities/bug/op_set_title_test.go b/entities/bug/op_set_title_test.go index 7960ec4f..82425ab4 100644 --- a/entities/bug/op_set_title_test.go +++ b/entities/bug/op_set_title_test.go @@ -4,11 +4,12 @@ import ( "testing" "github.com/MichaelMure/git-bug/entities/identity" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" ) func TestSetTitleSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *SetTitleOperation { - return NewSetTitleOp(author, unixTime, "title", "was") + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*SetTitleOperation, entity.Resolvers) { + return NewSetTitleOp(author, unixTime, "title", "was"), nil }) } diff --git a/entities/bug/operation.go b/entities/bug/operation.go index a02fc780..41d80700 100644 --- a/entities/bug/operation.go +++ b/entities/bug/operation.go @@ -32,7 +32,7 @@ type Operation interface { var _ Operation = &dag.NoOpOperation[*Snapshot]{} var _ Operation = &dag.SetMetadataOperation[*Snapshot]{} -func operationUnmarshaller(raw json.RawMessage, resolvers entity.Resolvers) (dag.Operation, error) { +func operationUnmarshaler(raw json.RawMessage, resolvers entity.Resolvers) (dag.Operation, error) { var t struct { OperationType dag.OperationType `json:"type"` } |