aboutsummaryrefslogtreecommitdiffstats
path: root/bug/op_set_metadata_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-07-25 13:16:16 +0200
committerMichael Muré <batolettre@gmail.com>2022-07-25 13:27:17 +0200
commit3d454d9dc8ba2409046c0938618a70864e6eb8ef (patch)
tree8745f656cc8218654632ce003f997a39988d3043 /bug/op_set_metadata_test.go
parent2ade8fb1d570ddcb4aedc9386af46d208b129daa (diff)
downloadgit-bug-3d454d9dc8ba2409046c0938618a70864e6eb8ef.tar.gz
entity/dag: proper base operation for simplified implementation
- reduce boilerplace necessary to implement an operation - consolidate what an operation is in the core, which in turn pave the way for a generic cache layer mechanism - avoid the previously complex unmarshalling process - support operation metadata from the core - simplified testing
Diffstat (limited to 'bug/op_set_metadata_test.go')
-rw-r--r--bug/op_set_metadata_test.go126
1 files changed, 0 insertions, 126 deletions
diff --git a/bug/op_set_metadata_test.go b/bug/op_set_metadata_test.go
deleted file mode 100644
index 62c1c942..00000000
--- a/bug/op_set_metadata_test.go
+++ /dev/null
@@ -1,126 +0,0 @@
-package bug
-
-import (
- "encoding/json"
- "testing"
- "time"
-
- "github.com/MichaelMure/git-bug/identity"
- "github.com/MichaelMure/git-bug/repository"
-
- "github.com/stretchr/testify/require"
-)
-
-func TestSetMetadata(t *testing.T) {
- snapshot := Snapshot{}
-
- repo := repository.NewMockRepo()
-
- rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr")
- require.NoError(t, err)
-
- unix := time.Now().Unix()
-
- create := NewCreateOp(rene, unix, "title", "create", nil)
- create.SetMetadata("key", "value")
- create.Apply(&snapshot)
- snapshot.Operations = append(snapshot.Operations, create)
-
- id1 := create.Id()
- require.NoError(t, id1.Validate())
-
- comment := NewAddCommentOp(rene, unix, "comment", nil)
- comment.SetMetadata("key2", "value2")
- comment.Apply(&snapshot)
- snapshot.Operations = append(snapshot.Operations, comment)
-
- id2 := comment.Id()
- require.NoError(t, id2.Validate())
-
- op1 := NewSetMetadataOp(rene, unix, id1, map[string]string{
- "key": "override",
- "key2": "value",
- })
-
- op1.Apply(&snapshot)
- snapshot.Operations = append(snapshot.Operations, op1)
-
- createMetadata := snapshot.Operations[0].AllMetadata()
- require.Len(t, createMetadata, 2)
- // original key is not overrided
- require.Equal(t, createMetadata["key"], "value")
- // new key is set
- require.Equal(t, createMetadata["key2"], "value")
-
- commentMetadata := snapshot.Operations[1].AllMetadata()
- require.Len(t, commentMetadata, 1)
- require.Equal(t, commentMetadata["key2"], "value2")
-
- op2 := NewSetMetadataOp(rene, unix, id2, map[string]string{
- "key2": "value",
- "key3": "value3",
- })
-
- op2.Apply(&snapshot)
- snapshot.Operations = append(snapshot.Operations, op2)
-
- createMetadata = snapshot.Operations[0].AllMetadata()
- require.Len(t, createMetadata, 2)
- require.Equal(t, createMetadata["key"], "value")
- require.Equal(t, createMetadata["key2"], "value")
-
- commentMetadata = snapshot.Operations[1].AllMetadata()
- require.Len(t, commentMetadata, 2)
- // original key is not overrided
- require.Equal(t, commentMetadata["key2"], "value2")
- // new key is set
- require.Equal(t, commentMetadata["key3"], "value3")
-
- op3 := NewSetMetadataOp(rene, unix, id1, map[string]string{
- "key": "override",
- "key2": "override",
- })
-
- op3.Apply(&snapshot)
- snapshot.Operations = append(snapshot.Operations, op3)
-
- createMetadata = snapshot.Operations[0].AllMetadata()
- require.Len(t, createMetadata, 2)
- // original key is not overrided
- require.Equal(t, createMetadata["key"], "value")
- // previously set key is not overrided
- require.Equal(t, createMetadata["key2"], "value")
-
- commentMetadata = snapshot.Operations[1].AllMetadata()
- require.Len(t, commentMetadata, 2)
- require.Equal(t, commentMetadata["key2"], "value2")
- require.Equal(t, commentMetadata["key3"], "value3")
-}
-
-func TestSetMetadataSerialize(t *testing.T) {
- repo := repository.NewMockRepo()
-
- rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr")
- require.NoError(t, err)
-
- unix := time.Now().Unix()
- before := NewSetMetadataOp(rene, unix, "message", map[string]string{
- "key1": "value1",
- "key2": "value2",
- })
-
- data, err := json.Marshal(before)
- require.NoError(t, err)
-
- var after SetMetadataOperation
- err = json.Unmarshal(data, &after)
- require.NoError(t, err)
-
- // enforce creating the ID
- before.Id()
-
- // Replace the identity as it's not serialized
- after.Author_ = rene
-
- require.Equal(t, before, &after)
-}