(t *testing.T, tctx *TestContext, name string, c *github.Commit)
| 111 | } |
| 112 | |
| 113 | func assertPatchResult(t *testing.T, tctx *TestContext, name string, c *github.Commit) { |
| 114 | expected := entriesToMap(tctx.BaseTree.Entries) |
| 115 | |
| 116 | root := filepath.Join("testdata", "patches", name) + string(filepath.Separator) |
| 117 | if err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error { |
| 118 | if err != nil { |
| 119 | return err |
| 120 | } |
| 121 | if d.IsDir() { |
| 122 | return nil |
| 123 | } |
| 124 | |
| 125 | relpath := filepath.ToSlash(strings.TrimPrefix(path, root)) |
| 126 | if path, ok := strings.CutSuffix(relpath, DeletedExt); ok { |
| 127 | delete(expected, path) |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | info, err := d.Info() |
| 132 | if err != nil { |
| 133 | return err |
| 134 | } |
| 135 | |
| 136 | var content []byte |
| 137 | if info.Mode()&fs.ModeSymlink > 0 { |
| 138 | target, err := os.Readlink(path) |
| 139 | if err != nil { |
| 140 | return err |
| 141 | } |
| 142 | content = []byte(target) |
| 143 | } else { |
| 144 | content, err = os.ReadFile(path) |
| 145 | if err != nil { |
| 146 | return err |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | expected[relpath] = treeFile{ |
| 151 | Mode: getGitMode(info), |
| 152 | Content: content, |
| 153 | } |
| 154 | |
| 155 | return nil |
| 156 | }); err != nil { |
| 157 | t.Fatalf("error listing expected files: %v", err) |
| 158 | } |
| 159 | |
| 160 | actualTree, _, err := tctx.Client.Git.GetTree(tctx, tctx.Repo.Owner, tctx.Repo.Name, c.GetTree().GetSHA(), true) |
| 161 | if err != nil { |
| 162 | t.Fatalf("error getting actual tree: %v", err) |
| 163 | } |
| 164 | |
| 165 | actual := entriesToMap(actualTree.Entries) |
| 166 | for path, file := range actual { |
| 167 | expectedFile, ok := expected[path] |
| 168 | if !ok { |
| 169 | t.Errorf("unexpected file %s", path) |
| 170 | continue |
no test coverage detected