2021-01-04 01:59:25 +03:00
|
|
|
package dag
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2021-02-09 12:46:33 +03:00
|
|
|
|
|
|
|
"github.com/MichaelMure/git-bug/identity"
|
2021-01-04 01:59:25 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestOperationPackReadWrite(t *testing.T) {
|
2021-02-14 12:02:01 +03:00
|
|
|
repo, id1, _, resolver, def := makeTestContext()
|
2021-01-04 01:59:25 +03:00
|
|
|
|
|
|
|
opp := &operationPack{
|
|
|
|
Author: id1,
|
|
|
|
Operations: []Operation{
|
|
|
|
newOp1(id1, "foo"),
|
|
|
|
newOp2(id1, "bar"),
|
|
|
|
},
|
|
|
|
CreateTime: 123,
|
|
|
|
EditTime: 456,
|
|
|
|
}
|
|
|
|
|
|
|
|
commitHash, err := opp.Write(def, repo)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
commit, err := repo.ReadCommit(commitHash)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-02-14 12:02:01 +03:00
|
|
|
opp2, err := readOperationPack(def, repo, resolver, commit)
|
2021-01-04 01:59:25 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, opp, opp2)
|
|
|
|
|
|
|
|
// make sure we get the same Id with the same data
|
|
|
|
opp3 := &operationPack{
|
|
|
|
Author: id1,
|
|
|
|
Operations: []Operation{
|
|
|
|
newOp1(id1, "foo"),
|
|
|
|
newOp2(id1, "bar"),
|
|
|
|
},
|
|
|
|
CreateTime: 123,
|
|
|
|
EditTime: 456,
|
|
|
|
}
|
|
|
|
require.Equal(t, opp.Id(), opp3.Id())
|
|
|
|
}
|
2021-02-09 12:46:33 +03:00
|
|
|
|
|
|
|
func TestOperationPackSignedReadWrite(t *testing.T) {
|
2021-02-14 12:02:01 +03:00
|
|
|
repo, id1, _, resolver, def := makeTestContext()
|
2021-02-09 12:46:33 +03:00
|
|
|
|
|
|
|
err := id1.(*identity.Identity).Mutate(repo, func(orig *identity.Mutator) {
|
|
|
|
orig.Keys = append(orig.Keys, identity.GenerateKey())
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
opp := &operationPack{
|
|
|
|
Author: id1,
|
|
|
|
Operations: []Operation{
|
|
|
|
newOp1(id1, "foo"),
|
|
|
|
newOp2(id1, "bar"),
|
|
|
|
},
|
|
|
|
CreateTime: 123,
|
|
|
|
EditTime: 456,
|
|
|
|
}
|
|
|
|
|
|
|
|
commitHash, err := opp.Write(def, repo)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
commit, err := repo.ReadCommit(commitHash)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-02-14 12:02:01 +03:00
|
|
|
opp2, err := readOperationPack(def, repo, resolver, commit)
|
2021-02-09 12:46:33 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, opp, opp2)
|
|
|
|
|
|
|
|
// make sure we get the same Id with the same data
|
|
|
|
opp3 := &operationPack{
|
|
|
|
Author: id1,
|
|
|
|
Operations: []Operation{
|
|
|
|
newOp1(id1, "foo"),
|
|
|
|
newOp2(id1, "bar"),
|
|
|
|
},
|
|
|
|
CreateTime: 123,
|
|
|
|
EditTime: 456,
|
|
|
|
}
|
|
|
|
require.Equal(t, opp.Id(), opp3.Id())
|
|
|
|
}
|