diff options
author | Michael Muré <batolettre@gmail.com> | 2020-11-08 19:15:06 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2021-02-14 12:17:44 +0100 |
commit | 7163b2283b4542a4d4abfe9a71963f122322bde7 (patch) | |
tree | 93a52a65c5ba1fd3e4112b2aa53c2c438bb5400c /bug/op_edit_comment_test.go | |
parent | 5ae8a132772385c903a62de2ceec02a97f108a01 (diff) | |
download | git-bug-7163b2283b4542a4d4abfe9a71963f122322bde7.tar.gz |
bug: Id from first operation data, not git + remove root link
Diffstat (limited to 'bug/op_edit_comment_test.go')
-rw-r--r-- | bug/op_edit_comment_test.go | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/bug/op_edit_comment_test.go b/bug/op_edit_comment_test.go index 263111f9..92ee7539 100644 --- a/bug/op_edit_comment_test.go +++ b/bug/op_edit_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" @@ -16,8 +15,8 @@ func TestEdit(t *testing.T) { snapshot := Snapshot{} repo := repository.NewMockRepo() - rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") - err := rene.Commit(repo) + + rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr") require.NoError(t, err) unix := time.Now().Unix() @@ -47,59 +46,59 @@ func TestEdit(t *testing.T) { edit := NewEditCommentOp(rene, unix, id1, "create edited", nil) edit.Apply(&snapshot) - assert.Equal(t, len(snapshot.Timeline), 4) - assert.Equal(t, len(snapshot.Timeline[0].(*CreateTimelineItem).History), 2) - assert.Equal(t, len(snapshot.Timeline[1].(*AddCommentTimelineItem).History), 1) - assert.Equal(t, len(snapshot.Timeline[3].(*AddCommentTimelineItem).History), 1) - assert.Equal(t, snapshot.Comments[0].Message, "create edited") - assert.Equal(t, snapshot.Comments[1].Message, "comment 1") - assert.Equal(t, snapshot.Comments[2].Message, "comment 2") + require.Equal(t, len(snapshot.Timeline), 4) + require.Equal(t, len(snapshot.Timeline[0].(*CreateTimelineItem).History), 2) + require.Equal(t, len(snapshot.Timeline[1].(*AddCommentTimelineItem).History), 1) + require.Equal(t, len(snapshot.Timeline[3].(*AddCommentTimelineItem).History), 1) + require.Equal(t, snapshot.Comments[0].Message, "create edited") + require.Equal(t, snapshot.Comments[1].Message, "comment 1") + require.Equal(t, snapshot.Comments[2].Message, "comment 2") edit2 := NewEditCommentOp(rene, unix, id2, "comment 1 edited", nil) edit2.Apply(&snapshot) - assert.Equal(t, len(snapshot.Timeline), 4) - assert.Equal(t, len(snapshot.Timeline[0].(*CreateTimelineItem).History), 2) - assert.Equal(t, len(snapshot.Timeline[1].(*AddCommentTimelineItem).History), 2) - assert.Equal(t, len(snapshot.Timeline[3].(*AddCommentTimelineItem).History), 1) - assert.Equal(t, snapshot.Comments[0].Message, "create edited") - assert.Equal(t, snapshot.Comments[1].Message, "comment 1 edited") - assert.Equal(t, snapshot.Comments[2].Message, "comment 2") + require.Equal(t, len(snapshot.Timeline), 4) + require.Equal(t, len(snapshot.Timeline[0].(*CreateTimelineItem).History), 2) + require.Equal(t, len(snapshot.Timeline[1].(*AddCommentTimelineItem).History), 2) + require.Equal(t, len(snapshot.Timeline[3].(*AddCommentTimelineItem).History), 1) + require.Equal(t, snapshot.Comments[0].Message, "create edited") + require.Equal(t, snapshot.Comments[1].Message, "comment 1 edited") + require.Equal(t, snapshot.Comments[2].Message, "comment 2") edit3 := NewEditCommentOp(rene, unix, id3, "comment 2 edited", nil) edit3.Apply(&snapshot) - assert.Equal(t, len(snapshot.Timeline), 4) - assert.Equal(t, len(snapshot.Timeline[0].(*CreateTimelineItem).History), 2) - assert.Equal(t, len(snapshot.Timeline[1].(*AddCommentTimelineItem).History), 2) - assert.Equal(t, len(snapshot.Timeline[3].(*AddCommentTimelineItem).History), 2) - assert.Equal(t, snapshot.Comments[0].Message, "create edited") - assert.Equal(t, snapshot.Comments[1].Message, "comment 1 edited") - assert.Equal(t, snapshot.Comments[2].Message, "comment 2 edited") + require.Equal(t, len(snapshot.Timeline), 4) + require.Equal(t, len(snapshot.Timeline[0].(*CreateTimelineItem).History), 2) + require.Equal(t, len(snapshot.Timeline[1].(*AddCommentTimelineItem).History), 2) + require.Equal(t, len(snapshot.Timeline[3].(*AddCommentTimelineItem).History), 2) + require.Equal(t, snapshot.Comments[0].Message, "create edited") + require.Equal(t, snapshot.Comments[1].Message, "comment 1 edited") + require.Equal(t, snapshot.Comments[2].Message, "comment 2 edited") } func TestEditCommentSerialize(t *testing.T) { repo := repository.NewMockRepo() - rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") - err := rene.Commit(repo) + + rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr") require.NoError(t, err) unix := time.Now().Unix() before := NewEditCommentOp(rene, unix, "target", "message", nil) data, err := json.Marshal(before) - assert.NoError(t, err) + require.NoError(t, err) var after EditCommentOperation 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.base().Author.Id()) + require.Equal(t, rene.Id(), after.base().Author.Id()) after.Author = rene - assert.Equal(t, before, &after) + require.Equal(t, before, &after) } |