From 14b240af8fef269d2c1d5dde2fff192b656c50f3 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 20 Jan 2019 15:41:27 +0100 Subject: identity: more cleaning and fixes after a code review --- bug/operation_pack_test.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'bug/operation_pack_test.go') diff --git a/bug/operation_pack_test.go b/bug/operation_pack_test.go index 48f9f80c..8a8c7e62 100644 --- a/bug/operation_pack_test.go +++ b/bug/operation_pack_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/MichaelMure/git-bug/util/git" - "github.com/go-test/deep" + "github.com/stretchr/testify/assert" ) func TestOperationPackSerialize(t *testing.T) { @@ -21,9 +21,7 @@ func TestOperationPackSerialize(t *testing.T) { opMeta.SetMetadata("key", "value") opp.Append(opMeta) - if len(opMeta.Metadata) != 1 { - t.Fatal() - } + assert.Equal(t, 1, len(opMeta.Metadata)) opFile := NewCreateOp(rene, unix, "title", "message", []git.Hash{ "abcdef", @@ -31,23 +29,14 @@ func TestOperationPackSerialize(t *testing.T) { }) opp.Append(opFile) - if len(opFile.Files) != 2 { - t.Fatal() - } + assert.Equal(t, 2, len(opFile.Files)) data, err := json.Marshal(opp) - if err != nil { - t.Fatal(err) - } + assert.NoError(t, err) var opp2 *OperationPack err = json.Unmarshal(data, &opp2) - if err != nil { - t.Fatal(err) - } - - deep.CompareUnexportedFields = false - if diff := deep.Equal(opp, opp2); diff != nil { - t.Fatal(diff) - } + + assert.NoError(t, err) + assert.Equal(t, opp, opp2) } -- cgit From d2483d83dd52365741f51eca106aa18c4e8d6420 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 16 Feb 2019 17:32:30 +0100 Subject: identity: I can compile again !! --- bug/operation_pack_test.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'bug/operation_pack_test.go') diff --git a/bug/operation_pack_test.go b/bug/operation_pack_test.go index 8a8c7e62..09d159af 100644 --- a/bug/operation_pack_test.go +++ b/bug/operation_pack_test.go @@ -3,27 +3,37 @@ package bug import ( "encoding/json" "testing" + "time" + "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/util/git" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestOperationPackSerialize(t *testing.T) { opp := &OperationPack{} + rene := identity.NewBare("René Descartes", "rene@descartes.fr") + createOp := NewCreateOp(rene, time.Now().Unix(), "title", "message", nil) + setTitleOp := NewSetTitleOp(rene, time.Now().Unix(), "title2", "title1") + addCommentOp := NewAddCommentOp(rene, time.Now().Unix(), "message2", nil) + setStatusOp := NewSetStatusOp(rene, time.Now().Unix(), ClosedStatus) + labelChangeOp := NewLabelChangeOperation(rene, time.Now().Unix(), []Label{"added"}, []Label{"removed"}) + opp.Append(createOp) opp.Append(setTitleOp) opp.Append(addCommentOp) opp.Append(setStatusOp) opp.Append(labelChangeOp) - opMeta := NewCreateOp(rene, unix, "title", "message", nil) + opMeta := NewSetTitleOp(rene, time.Now().Unix(), "title3", "title2") opMeta.SetMetadata("key", "value") opp.Append(opMeta) assert.Equal(t, 1, len(opMeta.Metadata)) - opFile := NewCreateOp(rene, unix, "title", "message", []git.Hash{ + opFile := NewAddCommentOp(rene, time.Now().Unix(), "message", []git.Hash{ "abcdef", "ghijkl", }) @@ -36,7 +46,16 @@ func TestOperationPackSerialize(t *testing.T) { var opp2 *OperationPack err = json.Unmarshal(data, &opp2) - assert.NoError(t, err) + + ensureHash(t, opp) + assert.Equal(t, opp, opp2) } + +func ensureHash(t *testing.T, opp *OperationPack) { + for _, op := range opp.Operations { + _, err := op.Hash() + require.NoError(t, err) + } +} -- cgit