diff options
Diffstat (limited to 'bug')
-rw-r--r-- | bug/op_add_comment_test.go | 15 | ||||
-rw-r--r-- | bug/op_create_test.go | 17 | ||||
-rw-r--r-- | bug/op_edit_comment_test.go | 20 | ||||
-rw-r--r-- | bug/op_label_change_test.go | 17 | ||||
-rw-r--r-- | bug/op_noop_test.go | 17 | ||||
-rw-r--r-- | bug/op_set_metadata_test.go | 21 | ||||
-rw-r--r-- | bug/op_set_status_test.go | 17 | ||||
-rw-r--r-- | bug/op_set_title_test.go | 17 | ||||
-rw-r--r-- | bug/operation_pack.go | 11 | ||||
-rw-r--r-- | bug/operation_pack_test.go | 29 | ||||
-rw-r--r-- | bug/operation_test.go | 12 |
11 files changed, 150 insertions, 43 deletions
diff --git a/bug/op_add_comment_test.go b/bug/op_add_comment_test.go index 60364cf1..8bcc64e1 100644 --- a/bug/op_add_comment_test.go +++ b/bug/op_add_comment_test.go @@ -6,12 +6,18 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" ) func TestAddCommentSerialize(t *testing.T) { - var rene = identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + unix := time.Now().Unix() before := NewAddCommentOp(rene, unix, "message", nil) @@ -22,9 +28,12 @@ func TestAddCommentSerialize(t *testing.T) { err = json.Unmarshal(data, &after) assert.NoError(t, err) - // enforce creating the IDs + // enforce creating the ID before.Id() - rene.Id() + + // Replace the identity stub with the real thing + assert.Equal(t, rene.Id(), after.base().Author.Id()) + after.Author = rene assert.Equal(t, before, &after) } diff --git a/bug/op_create_test.go b/bug/op_create_test.go index ad9a30fd..f68b7637 100644 --- a/bug/op_create_test.go +++ b/bug/op_create_test.go @@ -6,14 +6,16 @@ import ( "time" "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/timestamp" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCreate(t *testing.T) { snapshot := Snapshot{} - rene := identity.NewBare("René Descartes", "rene@descartes.fr") + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") unix := time.Now().Unix() create := NewCreateOp(rene, unix, "title", "message", nil) @@ -50,7 +52,11 @@ func TestCreate(t *testing.T) { } func TestCreateSerialize(t *testing.T) { - var rene = identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + unix := time.Now().Unix() before := NewCreateOp(rene, unix, "title", "message", nil) @@ -61,9 +67,12 @@ func TestCreateSerialize(t *testing.T) { err = json.Unmarshal(data, &after) assert.NoError(t, err) - // enforce creating the IDs + // enforce creating the ID before.Id() - rene.Id() + + // Replace the identity stub with the real thing + assert.Equal(t, rene.Id(), after.base().Author.Id()) + after.Author = rene assert.Equal(t, before, &after) } diff --git a/bug/op_edit_comment_test.go b/bug/op_edit_comment_test.go index abd550cb..583ba656 100644 --- a/bug/op_edit_comment_test.go +++ b/bug/op_edit_comment_test.go @@ -9,12 +9,17 @@ import ( "github.com/stretchr/testify/require" "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" ) func TestEdit(t *testing.T) { snapshot := Snapshot{} - rene := identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + unix := time.Now().Unix() create := NewCreateOp(rene, unix, "title", "create", nil) @@ -74,7 +79,11 @@ func TestEdit(t *testing.T) { } func TestEditCommentSerialize(t *testing.T) { - var rene = identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + unix := time.Now().Unix() before := NewEditCommentOp(rene, unix, "target", "message", nil) @@ -85,9 +94,12 @@ func TestEditCommentSerialize(t *testing.T) { err = json.Unmarshal(data, &after) assert.NoError(t, err) - // enforce creating the IDs + // enforce creating the ID before.Id() - rene.Id() + + // Replace the identity stub with the real thing + assert.Equal(t, rene.Id(), after.base().Author.Id()) + after.Author = rene assert.Equal(t, before, &after) } diff --git a/bug/op_label_change_test.go b/bug/op_label_change_test.go index 2a93e362..c98b2207 100644 --- a/bug/op_label_change_test.go +++ b/bug/op_label_change_test.go @@ -5,12 +5,20 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" + "github.com/stretchr/testify/assert" ) func TestLabelChangeSerialize(t *testing.T) { - var rene = identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + unix := time.Now().Unix() before := NewLabelChangeOperation(rene, unix, []Label{"added"}, []Label{"removed"}) @@ -21,9 +29,12 @@ func TestLabelChangeSerialize(t *testing.T) { err = json.Unmarshal(data, &after) assert.NoError(t, err) - // enforce creating the IDs + // enforce creating the ID before.Id() - rene.Id() + + // Replace the identity stub with the real thing + assert.Equal(t, rene.Id(), after.base().Author.Id()) + after.Author = rene assert.Equal(t, before, &after) } diff --git a/bug/op_noop_test.go b/bug/op_noop_test.go index ea815948..0e34c961 100644 --- a/bug/op_noop_test.go +++ b/bug/op_noop_test.go @@ -5,12 +5,20 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" + "github.com/stretchr/testify/assert" ) func TestNoopSerialize(t *testing.T) { - var rene = identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + unix := time.Now().Unix() before := NewNoOpOp(rene, unix) @@ -21,9 +29,12 @@ func TestNoopSerialize(t *testing.T) { err = json.Unmarshal(data, &after) assert.NoError(t, err) - // enforce creating the IDs + // enforce creating the ID before.Id() - rene.Id() + + // Replace the identity stub with the real thing + assert.Equal(t, rene.Id(), after.base().Author.Id()) + 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 389e91ac..d7711249 100644 --- a/bug/op_set_metadata_test.go +++ b/bug/op_set_metadata_test.go @@ -6,6 +6,8 @@ import ( "time" "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -13,7 +15,11 @@ import ( func TestSetMetadata(t *testing.T) { snapshot := Snapshot{} - rene := identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + unix := time.Now().Unix() create := NewCreateOp(rene, unix, "title", "create", nil) @@ -93,7 +99,11 @@ func TestSetMetadata(t *testing.T) { } func TestSetMetadataSerialize(t *testing.T) { - var rene = identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + unix := time.Now().Unix() before := NewSetMetadataOp(rene, unix, "message", map[string]string{ "key1": "value1", @@ -107,9 +117,12 @@ func TestSetMetadataSerialize(t *testing.T) { err = json.Unmarshal(data, &after) assert.NoError(t, err) - // enforce creating the IDs + // enforce creating the ID before.Id() - rene.Id() + + // Replace the identity stub with the real thing + assert.Equal(t, rene.Id(), after.base().Author.Id()) + after.Author = rene assert.Equal(t, before, &after) } diff --git a/bug/op_set_status_test.go b/bug/op_set_status_test.go index ea032184..cdea2dd2 100644 --- a/bug/op_set_status_test.go +++ b/bug/op_set_status_test.go @@ -5,12 +5,20 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" + "github.com/stretchr/testify/assert" ) func TestSetStatusSerialize(t *testing.T) { - var rene = identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + unix := time.Now().Unix() before := NewSetStatusOp(rene, unix, ClosedStatus) @@ -21,9 +29,12 @@ func TestSetStatusSerialize(t *testing.T) { err = json.Unmarshal(data, &after) assert.NoError(t, err) - // enforce creating the IDs + // enforce creating the ID before.Id() - rene.Id() + + // Replace the identity stub with the real thing + assert.Equal(t, rene.Id(), after.base().Author.Id()) + after.Author = rene assert.Equal(t, before, &after) } diff --git a/bug/op_set_title_test.go b/bug/op_set_title_test.go index 19cbb12b..368ada61 100644 --- a/bug/op_set_title_test.go +++ b/bug/op_set_title_test.go @@ -5,12 +5,20 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" + "github.com/stretchr/testify/assert" ) func TestSetTitleSerialize(t *testing.T) { - var rene = identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + unix := time.Now().Unix() before := NewSetTitleOp(rene, unix, "title", "was") @@ -21,9 +29,12 @@ func TestSetTitleSerialize(t *testing.T) { err = json.Unmarshal(data, &after) assert.NoError(t, err) - // enforce creating the IDs + // enforce creating the ID before.Id() - rene.Id() + + // Replace the identity stub with the real thing + assert.Equal(t, rene.Id(), after.base().Author.Id()) + after.Author = rene assert.Equal(t, before, &after) } diff --git a/bug/operation_pack.go b/bug/operation_pack.go index 6a134b94..0bd3fb7d 100644 --- a/bug/operation_pack.go +++ b/bug/operation_pack.go @@ -9,7 +9,9 @@ import ( "github.com/MichaelMure/git-bug/repository" ) -const formatVersion = 1 +// 1: original format +// 2: no more legacy identities +const formatVersion = 2 // OperationPack represent an ordered set of operation to apply // to a Bug. These operations are stored in a single Git commit. @@ -44,8 +46,11 @@ func (opp *OperationPack) UnmarshalJSON(data []byte) error { return err } - if aux.Version != formatVersion { - return fmt.Errorf("unknown format version %v", aux.Version) + if aux.Version < formatVersion { + return fmt.Errorf("outdated repository format, please use https://github.com/MichaelMure/git-bug-migration to upgrade") + } + if aux.Version > formatVersion { + return fmt.Errorf("your version of git-bug is too old for this repository (version %v), please upgrade to the latest version", aux.Version) } for _, raw := range aux.Operations { diff --git a/bug/operation_pack_test.go b/bug/operation_pack_test.go index b6707152..6aab0097 100644 --- a/bug/operation_pack_test.go +++ b/bug/operation_pack_test.go @@ -15,7 +15,11 @@ import ( func TestOperationPackSerialize(t *testing.T) { opp := &OperationPack{} - rene := identity.NewBare("René Descartes", "rene@descartes.fr") + repo := repository.NewMockRepoForTest() + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) + 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) @@ -49,16 +53,27 @@ func TestOperationPackSerialize(t *testing.T) { err = json.Unmarshal(data, &opp2) assert.NoError(t, err) - ensureIDs(t, opp) + ensureIds(opp) + ensureAuthors(t, opp, opp2) assert.Equal(t, opp, opp2) } -func ensureIDs(t *testing.T, opp *OperationPack) { +func ensureIds(opp *OperationPack) { for _, op := range opp.Operations { - id := op.Id() - require.NoError(t, id.Validate()) - id = op.GetAuthor().Id() - require.NoError(t, id.Validate()) + op.Id() + } +} + +func ensureAuthors(t *testing.T, opp1 *OperationPack, opp2 *OperationPack) { + require.Equal(t, len(opp1.Operations), len(opp2.Operations)) + for i := 0; i < len(opp1.Operations); i++ { + op1 := opp1.Operations[i] + op2 := opp2.Operations[i] + + // ensure we have equivalent authors (IdentityStub vs Identity) then + // enforce equality + require.Equal(t, op1.base().Author.Id(), op2.base().Author.Id()) + op1.base().Author = op2.base().Author } } diff --git a/bug/operation_test.go b/bug/operation_test.go index 64bff41f..20799bb1 100644 --- a/bug/operation_test.go +++ b/bug/operation_test.go @@ -88,32 +88,32 @@ func TestID(t *testing.T) { } for _, repo := range repos { - rene := identity.NewBare("René Descartes", "rene@descartes.fr") + rene := identity.NewIdentity("René Descartes", "rene@descartes.fr") + err := rene.Commit(repo) + require.NoError(t, err) b, op, err := Create(rene, time.Now().Unix(), "title", "message") - require.Nil(t, err) + require.NoError(t, err) id1 := op.Id() require.NoError(t, id1.Validate()) err = b.Commit(repo) - require.Nil(t, err) + require.NoError(t, err) op2 := b.FirstOp() id2 := op2.Id() require.NoError(t, id2.Validate()) - require.Equal(t, id1, id2) b2, err := ReadLocal(repo, b.Id()) - require.Nil(t, err) + require.NoError(t, err) op3 := b2.FirstOp() id3 := op3.Id() require.NoError(t, id3.Validate()) - require.Equal(t, id1, id3) } } |