From 2e1a5e246ee3589c2f664a62ebd06be7dc69c229 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 7 Aug 2019 15:31:38 +0200 Subject: bug: compute op's ID based on the serialized data on disk --- bug/op_edit_comment_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'bug/op_edit_comment_test.go') diff --git a/bug/op_edit_comment_test.go b/bug/op_edit_comment_test.go index ab0f2d21..9e8739da 100644 --- a/bug/op_edit_comment_test.go +++ b/bug/op_edit_comment_test.go @@ -20,14 +20,14 @@ func TestEdit(t *testing.T) { create := NewCreateOp(rene, unix, "title", "create", nil) create.Apply(&snapshot) - hash1, err := create.Hash() - require.NoError(t, err) + hash1 := create.ID() + require.True(t, IDIsValid(hash1)) comment1 := NewAddCommentOp(rene, unix, "comment 1", nil) comment1.Apply(&snapshot) - hash2, err := comment1.Hash() - require.NoError(t, err) + hash2 := comment1.ID() + require.True(t, IDIsValid(hash2)) // add another unrelated op in between setTitle := NewSetTitleOp(rene, unix, "edited title", "title") @@ -36,8 +36,8 @@ func TestEdit(t *testing.T) { comment2 := NewAddCommentOp(rene, unix, "comment 2", nil) comment2.Apply(&snapshot) - hash3, err := comment2.Hash() - require.NoError(t, err) + hash3 := comment2.ID() + require.True(t, IDIsValid(hash3)) edit := NewEditCommentOp(rene, unix, hash1, "create edited", nil) edit.Apply(&snapshot) @@ -85,5 +85,8 @@ func TestEditCommentSerialize(t *testing.T) { err = json.Unmarshal(data, &after) assert.NoError(t, err) + // enforce creating the ID + before.ID() + assert.Equal(t, before, &after) } -- cgit From 67a3752e176790e82a48706236f889cab4f8913d Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 11 Aug 2019 14:08:03 +0200 Subject: bug,entity: use a dedicated type to store IDs --- bug/op_edit_comment_test.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'bug/op_edit_comment_test.go') diff --git a/bug/op_edit_comment_test.go b/bug/op_edit_comment_test.go index 9e8739da..abd550cb 100644 --- a/bug/op_edit_comment_test.go +++ b/bug/op_edit_comment_test.go @@ -20,14 +20,14 @@ func TestEdit(t *testing.T) { create := NewCreateOp(rene, unix, "title", "create", nil) create.Apply(&snapshot) - hash1 := create.ID() - require.True(t, IDIsValid(hash1)) + id1 := create.Id() + require.NoError(t, id1.Validate()) comment1 := NewAddCommentOp(rene, unix, "comment 1", nil) comment1.Apply(&snapshot) - hash2 := comment1.ID() - require.True(t, IDIsValid(hash2)) + id2 := comment1.Id() + require.NoError(t, id2.Validate()) // add another unrelated op in between setTitle := NewSetTitleOp(rene, unix, "edited title", "title") @@ -36,10 +36,10 @@ func TestEdit(t *testing.T) { comment2 := NewAddCommentOp(rene, unix, "comment 2", nil) comment2.Apply(&snapshot) - hash3 := comment2.ID() - require.True(t, IDIsValid(hash3)) + id3 := comment2.Id() + require.NoError(t, id3.Validate()) - edit := NewEditCommentOp(rene, unix, hash1, "create edited", nil) + edit := NewEditCommentOp(rene, unix, id1, "create edited", nil) edit.Apply(&snapshot) assert.Equal(t, len(snapshot.Timeline), 4) @@ -50,7 +50,7 @@ func TestEdit(t *testing.T) { assert.Equal(t, snapshot.Comments[1].Message, "comment 1") assert.Equal(t, snapshot.Comments[2].Message, "comment 2") - edit2 := NewEditCommentOp(rene, unix, hash2, "comment 1 edited", nil) + edit2 := NewEditCommentOp(rene, unix, id2, "comment 1 edited", nil) edit2.Apply(&snapshot) assert.Equal(t, len(snapshot.Timeline), 4) @@ -61,7 +61,7 @@ func TestEdit(t *testing.T) { assert.Equal(t, snapshot.Comments[1].Message, "comment 1 edited") assert.Equal(t, snapshot.Comments[2].Message, "comment 2") - edit3 := NewEditCommentOp(rene, unix, hash3, "comment 2 edited", nil) + edit3 := NewEditCommentOp(rene, unix, id3, "comment 2 edited", nil) edit3.Apply(&snapshot) assert.Equal(t, len(snapshot.Timeline), 4) @@ -85,8 +85,9 @@ func TestEditCommentSerialize(t *testing.T) { err = json.Unmarshal(data, &after) assert.NoError(t, err) - // enforce creating the ID - before.ID() + // enforce creating the IDs + before.Id() + rene.Id() assert.Equal(t, before, &after) } -- cgit