op_label_change_test.go

 1package bug
 2
 3import (
 4	"encoding/json"
 5	"testing"
 6	"time"
 7
 8	"github.com/stretchr/testify/require"
 9
10	"github.com/MichaelMure/git-bug/identity"
11	"github.com/MichaelMure/git-bug/repository"
12
13	"github.com/stretchr/testify/assert"
14)
15
16func TestLabelChangeSerialize(t *testing.T) {
17	repo := repository.NewMockRepoForTest()
18	rene := identity.NewIdentity("René Descartes", "rene@descartes.fr")
19	err := rene.Commit(repo)
20	require.NoError(t, err)
21
22	unix := time.Now().Unix()
23	before := NewLabelChangeOperation(rene, unix, []Label{"added"}, []Label{"removed"})
24
25	data, err := json.Marshal(before)
26	assert.NoError(t, err)
27
28	var after LabelChangeOperation
29	err = json.Unmarshal(data, &after)
30	assert.NoError(t, err)
31
32	// enforce creating the ID
33	before.Id()
34
35	// Replace the identity stub with the real thing
36	assert.Equal(t, rene.Id(), after.base().Author.Id())
37	after.Author = rene
38
39	assert.Equal(t, before, &after)
40}