aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/delta_test.go
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-07-19 15:21:49 +0200
committerAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-07-19 15:21:49 +0200
commit4f713d10b2c6c182ab853184f7469912e9c85c92 (patch)
treeba2a569f49d6c7797e3072afc7bb3a3abe37159f /plumbing/format/packfile/delta_test.go
parent9775f829d6fb8026a2d73af89896a8f2cc5f7c50 (diff)
downloadgo-git-4f713d10b2c6c182ab853184f7469912e9c85c92.tar.gz
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)
+}