(t *testing.T)
| 160 | } |
| 161 | |
| 162 | func TestMutatingCanAccessGit(t *testing.T) { |
| 163 | ptyTests := []struct { |
| 164 | name string |
| 165 | hook string |
| 166 | out string |
| 167 | }{ |
| 168 | { |
| 169 | "stdout", |
| 170 | "#!/bin/sh \n git status", |
| 171 | "", |
| 172 | }, |
| 173 | { |
| 174 | "stderr", |
| 175 | "#!/bin/sh \n git status 1>&2", |
| 176 | "accesses-git: On branch main", |
| 177 | }, |
| 178 | } |
| 179 | for _, tt := range ptyTests { |
| 180 | t.Run(tt.name, func(t *testing.T) { |
| 181 | tempDir := initGitForPreCommit(t) |
| 182 | tempDir.MkdirAll(".quickhook", "pre-commit-mutating") |
| 183 | tempDir.WriteFile([]string{".quickhook", "pre-commit-mutating", "accesses-git"}, tt.hook) |
| 184 | |
| 185 | output, err := tempDir.ExecQuickhook("hook", "pre-commit") |
| 186 | assert.NoError(t, err) |
| 187 | if tt.out == "" { |
| 188 | assert.Empty(t, output) |
| 189 | } else { |
| 190 | assert.Contains(t, output, tt.out) |
| 191 | } |
| 192 | }) |
| 193 | } |
| 194 | } |
nothing calls this directly
no test coverage detected