|
1 | 1 | package object |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "sort" |
5 | 6 |
|
6 | 7 | "gopkg.in/src-d/go-git.v4/plumbing" |
@@ -82,6 +83,12 @@ func (s *ChangeSuite) TestInsert(c *C) { |
82 | 83 | c.Assert(len(p.FilePatches()[0].Chunks()), Equals, 1) |
83 | 84 | c.Assert(p.FilePatches()[0].Chunks()[0].Type(), Equals, diff.Add) |
84 | 85 |
|
| 86 | + p, err = change.PatchContext(context.Background()) |
| 87 | + c.Assert(err, IsNil) |
| 88 | + c.Assert(len(p.FilePatches()), Equals, 1) |
| 89 | + c.Assert(len(p.FilePatches()[0].Chunks()), Equals, 1) |
| 90 | + c.Assert(p.FilePatches()[0].Chunks()[0].Type(), Equals, diff.Add) |
| 91 | + |
85 | 92 | str := change.String() |
86 | 93 | c.Assert(str, Equals, "<Action: Insert, Path: examples/clone/main.go>") |
87 | 94 | } |
@@ -134,6 +141,12 @@ func (s *ChangeSuite) TestDelete(c *C) { |
134 | 141 | c.Assert(len(p.FilePatches()[0].Chunks()), Equals, 1) |
135 | 142 | c.Assert(p.FilePatches()[0].Chunks()[0].Type(), Equals, diff.Delete) |
136 | 143 |
|
| 144 | + p, err = change.PatchContext(context.Background()) |
| 145 | + c.Assert(err, IsNil) |
| 146 | + c.Assert(len(p.FilePatches()), Equals, 1) |
| 147 | + c.Assert(len(p.FilePatches()[0].Chunks()), Equals, 1) |
| 148 | + c.Assert(p.FilePatches()[0].Chunks()[0].Type(), Equals, diff.Delete) |
| 149 | + |
137 | 150 | str := change.String() |
138 | 151 | c.Assert(str, Equals, "<Action: Delete, Path: utils/difftree/difftree.go>") |
139 | 152 | } |
@@ -206,6 +219,18 @@ func (s *ChangeSuite) TestModify(c *C) { |
206 | 219 | c.Assert(p.FilePatches()[0].Chunks()[5].Type(), Equals, diff.Add) |
207 | 220 | c.Assert(p.FilePatches()[0].Chunks()[6].Type(), Equals, diff.Equal) |
208 | 221 |
|
| 222 | + p, err = change.PatchContext(context.Background()) |
| 223 | + c.Assert(err, IsNil) |
| 224 | + c.Assert(len(p.FilePatches()), Equals, 1) |
| 225 | + c.Assert(len(p.FilePatches()[0].Chunks()), Equals, 7) |
| 226 | + c.Assert(p.FilePatches()[0].Chunks()[0].Type(), Equals, diff.Equal) |
| 227 | + c.Assert(p.FilePatches()[0].Chunks()[1].Type(), Equals, diff.Delete) |
| 228 | + c.Assert(p.FilePatches()[0].Chunks()[2].Type(), Equals, diff.Add) |
| 229 | + c.Assert(p.FilePatches()[0].Chunks()[3].Type(), Equals, diff.Equal) |
| 230 | + c.Assert(p.FilePatches()[0].Chunks()[4].Type(), Equals, diff.Delete) |
| 231 | + c.Assert(p.FilePatches()[0].Chunks()[5].Type(), Equals, diff.Add) |
| 232 | + c.Assert(p.FilePatches()[0].Chunks()[6].Type(), Equals, diff.Equal) |
| 233 | + |
209 | 234 | str := change.String() |
210 | 235 | c.Assert(str, Equals, "<Action: Modify, Path: utils/difftree/difftree.go>") |
211 | 236 | } |
@@ -367,3 +392,39 @@ func (s *ChangeSuite) TestChangesSort(c *C) { |
367 | 392 | sort.Sort(changes) |
368 | 393 | c.Assert(changes.String(), Equals, expected) |
369 | 394 | } |
| 395 | + |
| 396 | +func (s *ChangeSuite) TestCancel(c *C) { |
| 397 | + // Commit a5078b19f08f63e7948abd0a5e2fb7d319d3a565 of the go-git |
| 398 | + // fixture inserted "examples/clone/main.go". |
| 399 | + // |
| 400 | + // On that commit, the "examples/clone" tree is |
| 401 | + // 6efca3ff41cab651332f9ebc0c96bb26be809615 |
| 402 | + // |
| 403 | + // and the "examples/colone/main.go" is |
| 404 | + // f95dc8f7923add1a8b9f72ecb1e8db1402de601a |
| 405 | + |
| 406 | + path := "examples/clone/main.go" |
| 407 | + name := "main.go" |
| 408 | + mode := filemode.Regular |
| 409 | + blob := plumbing.NewHash("f95dc8f7923add1a8b9f72ecb1e8db1402de601a") |
| 410 | + tree := plumbing.NewHash("6efca3ff41cab651332f9ebc0c96bb26be809615") |
| 411 | + |
| 412 | + change := &Change{ |
| 413 | + From: empty, |
| 414 | + To: ChangeEntry{ |
| 415 | + Name: path, |
| 416 | + Tree: s.tree(c, tree), |
| 417 | + TreeEntry: TreeEntry{ |
| 418 | + Name: name, |
| 419 | + Mode: mode, |
| 420 | + Hash: blob, |
| 421 | + }, |
| 422 | + }, |
| 423 | + } |
| 424 | + |
| 425 | + ctx, cancel := context.WithCancel(context.Background()) |
| 426 | + cancel() |
| 427 | + p, err := change.PatchContext(ctx) |
| 428 | + c.Assert(p, IsNil) |
| 429 | + c.Assert(err, ErrorMatches, "operation canceled") |
| 430 | +} |
0 commit comments