diff options
author | Michael Muré <batolettre@gmail.com> | 2019-01-20 15:41:27 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-03-01 22:40:22 +0100 |
commit | 14b240af8fef269d2c1d5dde2fff192b656c50f3 (patch) | |
tree | 4f6ea032789d811cd019bbb6c190c99a650084b2 /bug | |
parent | d10c76469d40f13e27739fd363145e89bf74c3e0 (diff) | |
download | git-bug-14b240af8fef269d2c1d5dde2fff192b656c50f3.tar.gz |
identity: more cleaning and fixes after a code review
Diffstat (limited to 'bug')
-rw-r--r-- | bug/bug_actions_test.go | 2 | ||||
-rw-r--r-- | bug/op_create_test.go | 10 | ||||
-rw-r--r-- | bug/operation_pack.go | 6 | ||||
-rw-r--r-- | bug/operation_pack_test.go | 25 |
4 files changed, 16 insertions, 27 deletions
diff --git a/bug/bug_actions_test.go b/bug/bug_actions_test.go index 95ca01c9..af561bf6 100644 --- a/bug/bug_actions_test.go +++ b/bug/bug_actions_test.go @@ -50,7 +50,7 @@ func cleanupRepo(repo repository.Repo) error { func setupRepos(t testing.TB) (repoA, repoB, remote *repository.GitRepo) { repoA = createRepo(false) repoB = createRepo(false) - remote = createRepo(false) + remote = createRepo(true) remoteAddr := "file://" + remote.GetPath() diff --git a/bug/op_create_test.go b/bug/op_create_test.go index 31693a4a..065b81c5 100644 --- a/bug/op_create_test.go +++ b/bug/op_create_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/MichaelMure/git-bug/identity" - "github.com/go-test/deep" "github.com/stretchr/testify/assert" ) @@ -22,9 +21,7 @@ func TestCreate(t *testing.T) { create.Apply(&snapshot) hash, err := create.Hash() - if err != nil { - t.Fatal(err) - } + assert.NoError(t, err) comment := Comment{Author: rene, Message: "message", UnixTime: Timestamp(create.UnixTime)} @@ -42,10 +39,7 @@ func TestCreate(t *testing.T) { }, } - deep.CompareUnexportedFields = true - if diff := deep.Equal(snapshot, expected); diff != nil { - t.Fatal(diff) - } + assert.Equal(t, expected, snapshot) } func TestCreateSerialize(t *testing.T) { diff --git a/bug/operation_pack.go b/bug/operation_pack.go index 18b2a478..1ffc1d1a 100644 --- a/bug/operation_pack.go +++ b/bug/operation_pack.go @@ -139,6 +139,12 @@ func (opp *OperationPack) Validate() error { // Write will serialize and store the OperationPack as a git blob and return // its hash func (opp *OperationPack) Write(repo repository.Repo) (git.Hash, error) { + // make sure we don't write invalid data + err := opp.Validate() + if err != nil { + return "", errors.Wrap(err, "validation error") + } + // First, make sure that all the identities are properly Commit as well for _, op := range opp.Operations { err := op.base().Author.Commit(repo) diff --git a/bug/operation_pack_test.go b/bug/operation_pack_test.go index 48f9f80c..8a8c7e62 100644 --- a/bug/operation_pack_test.go +++ b/bug/operation_pack_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/MichaelMure/git-bug/util/git" - "github.com/go-test/deep" + "github.com/stretchr/testify/assert" ) func TestOperationPackSerialize(t *testing.T) { @@ -21,9 +21,7 @@ func TestOperationPackSerialize(t *testing.T) { opMeta.SetMetadata("key", "value") opp.Append(opMeta) - if len(opMeta.Metadata) != 1 { - t.Fatal() - } + assert.Equal(t, 1, len(opMeta.Metadata)) opFile := NewCreateOp(rene, unix, "title", "message", []git.Hash{ "abcdef", @@ -31,23 +29,14 @@ func TestOperationPackSerialize(t *testing.T) { }) opp.Append(opFile) - if len(opFile.Files) != 2 { - t.Fatal() - } + assert.Equal(t, 2, len(opFile.Files)) data, err := json.Marshal(opp) - if err != nil { - t.Fatal(err) - } + assert.NoError(t, err) var opp2 *OperationPack err = json.Unmarshal(data, &opp2) - if err != nil { - t.Fatal(err) - } - - deep.CompareUnexportedFields = false - if diff := deep.Equal(opp, opp2); diff != nil { - t.Fatal(diff) - } + + assert.NoError(t, err) + assert.Equal(t, opp, opp2) } |