TestRunCommandReceivesCredentialsViaEnv verifies the supported contract: the hook receives credentials through the USERNAME and PASSWORD environment variables.
(t *testing.T)
| 59 | // hook receives credentials through the USERNAME and PASSWORD environment |
| 60 | // variables. |
| 61 | func TestRunCommandReceivesCredentialsViaEnv(t *testing.T) { |
| 62 | if runtime.GOOS == "windows" { |
| 63 | t.Skip("uses POSIX shell") |
| 64 | } |
| 65 | |
| 66 | script := writeHookScript(t, `if [ "$USERNAME" = alice ] && [ "$PASSWORD" = secret ]; then |
| 67 | echo hook.action=auth |
| 68 | else |
| 69 | echo hook.action=block |
| 70 | fi |
| 71 | `) |
| 72 | |
| 73 | a := &HookAuth{ |
| 74 | Command: script, |
| 75 | Cred: hookCred{ |
| 76 | Username: "alice", |
| 77 | Password: "secret", |
| 78 | }, |
| 79 | } |
| 80 | |
| 81 | action, err := a.RunCommand() |
| 82 | if err != nil { |
| 83 | t.Fatalf("RunCommand returned error: %v", err) |
| 84 | } |
| 85 | if action != "auth" { |
| 86 | t.Fatalf("expected action %q, got %q", "auth", action) |
| 87 | } |
| 88 | } |
nothing calls this directly
no test coverage detected