(t *testing.T, tctx *TestContext, name string)
| 71 | } |
| 72 | |
| 73 | func runPatchTest(t *testing.T, tctx *TestContext, name string) { |
| 74 | f, err := os.Open(filepath.Join("testdata", "patches", name+".patch")) |
| 75 | if err != nil { |
| 76 | t.Fatalf("error opening patch file: %v", err) |
| 77 | } |
| 78 | defer f.Close() |
| 79 | |
| 80 | files, _, err := gitdiff.Parse(f) |
| 81 | if err != nil { |
| 82 | t.Fatalf("error parsing patch: %v", err) |
| 83 | } |
| 84 | |
| 85 | applier := NewApplier(tctx.Client, tctx.Repo, tctx.BaseCommit) |
| 86 | for _, file := range files { |
| 87 | if _, err := applier.Apply(tctx, file); err != nil { |
| 88 | t.Fatalf("error applying file patch: %s: %v", file.NewName, err) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | commit, err := applier.Commit(tctx, nil, &gitdiff.PatchHeader{ |
| 93 | Title: name, |
| 94 | }) |
| 95 | if err != nil { |
| 96 | t.Fatalf("error committing changes: %v", err) |
| 97 | } |
| 98 | |
| 99 | ref := NewReference(tctx.Client, tctx.Repo, tctx.Branch(name)) |
| 100 | if err := ref.Set(tctx, commit.GetSHA(), true); err != nil { |
| 101 | t.Fatalf("error creating ref: %v", err) |
| 102 | } |
| 103 | |
| 104 | assertPatchResult(t, tctx, name, commit) |
| 105 | } |
| 106 | |
| 107 | type treeFile struct { |
| 108 | Mode string |
no test coverage detected