(t *testing.T)
| 52 | } |
| 53 | |
| 54 | func TestPromptForInstall(t *testing.T) { |
| 55 | ptyTests := []struct { |
| 56 | name string |
| 57 | stdin string |
| 58 | expected bool |
| 59 | }{ |
| 60 | { |
| 61 | "yes", |
| 62 | "yes\n", |
| 63 | true, |
| 64 | }, |
| 65 | { |
| 66 | "short yes", |
| 67 | "y\n", |
| 68 | true, |
| 69 | }, |
| 70 | { |
| 71 | "no", |
| 72 | "no\n", |
| 73 | false, |
| 74 | }, |
| 75 | { |
| 76 | "short no", |
| 77 | "n\n", |
| 78 | false, |
| 79 | }, |
| 80 | { |
| 81 | "no input", |
| 82 | "", |
| 83 | false, |
| 84 | }, |
| 85 | } |
| 86 | for _, tt := range ptyTests { |
| 87 | t.Run(tt.name, func(t *testing.T) { |
| 88 | tempDir := test.NewTempDir(t, 0) |
| 89 | repo := &repo.Repo{Root: tempDir.Root} |
| 90 | |
| 91 | stdin := strings.NewReader(tt.stdin) |
| 92 | shouldInstall, err := promptForInstallShim(stdin, repo, ".git/hooks/pre-commit") |
| 93 | assert.NoError(t, err) |
| 94 | assert.Equal(t, tt.expected, shouldInstall) |
| 95 | }) |
| 96 | } |
| 97 | } |
nothing calls this directly
no test coverage detected