aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/delta_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-19 19:50:51 +0200
committerGitHub <noreply@github.com>2017-07-19 19:50:51 +0200
commit595dfe6e53a038da4949263ea2d9a7a0020c48b7 (patch)
tree886a6ecac521c80f2192c84bb0cc9c1a1e3517a6 /plumbing/format/packfile/delta_test.go
parentf0fb843efcf56c3df9dbbb47aaafe3e9c4815147 (diff)
parent4f713d10b2c6c182ab853184f7469912e9c85c92 (diff)
downloadgo-git-595dfe6e53a038da4949263ea2d9a7a0020c48b7.tar.gz
Merge pull request #492 from ajnavarro/fix/panic-in-invalid-delta
packfile: Avoid panics patching corrupted deltas.
Diffstat (limited to 'plumbing/format/packfile/delta_test.go')
-rw-r--r--plumbing/format/packfile/delta_test.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/plumbing/format/packfile/delta_test.go b/plumbing/format/packfile/delta_test.go
index 9ee3499..42b777a 100644
--- a/plumbing/format/packfile/delta_test.go
+++ b/plumbing/format/packfile/delta_test.go
@@ -1,7 +1,6 @@
package packfile
import (
- "fmt"
"math/rand"
. "gopkg.in/check.v1"
@@ -86,9 +85,28 @@ func (s *DeltaSuite) TestAddDelta(c *C) {
baseBuf := genBytes(t.base)
targetBuf := genBytes(t.target)
delta := DiffDelta(baseBuf, targetBuf)
- result := PatchDelta(baseBuf, delta)
+ result, err := PatchDelta(baseBuf, delta)
- c.Log(fmt.Printf("Executing test case: %s\n", t.description))
+ c.Log("Executing test case:", t.description)
+ c.Assert(err, IsNil)
c.Assert(result, DeepEquals, targetBuf)
}
}
+
+func (s *DeltaSuite) TestIncompleteDelta(c *C) {
+ for _, t := range s.testCases {
+ c.Log("Incomplete delta on:", t.description)
+ baseBuf := genBytes(t.base)
+ targetBuf := genBytes(t.target)
+ delta := DiffDelta(baseBuf, targetBuf)
+ delta = delta[:len(delta)-2]
+ result, err := PatchDelta(baseBuf, delta)
+ c.Assert(err, NotNil)
+ c.Assert(result, IsNil)
+ }
+
+ // check nil input too
+ result, err := PatchDelta(nil, nil)
+ c.Assert(err, NotNil)
+ c.Assert(result, IsNil)
+}