MCPcopy Create free account
hub / github.com/dirk/quickhook / TestMutatingCanAccessGit

Function TestMutatingCanAccessGit

hooks/pre_commit_test.go:162–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

160}
161
162func 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}

Callers

nothing calls this directly

Calls 5

initGitForPreCommitFunction · 0.85
MkdirAllMethod · 0.80
WriteFileMethod · 0.80
ExecQuickhookMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected