Repository: cli/cli
File: pkg/cmd/extension/command_test.go (Go)

Code before:
					return nil
				}
				return func(t *testing.T) {
					calls := em.InstallLocalCalls()
					assert.Equal(t, 1, len(calls))
					assert.Equal(t, localExtensionTempDir, normalizeDir(calls[0].Dir))
				}
			},
		},
		{
			name: "installing local extension without executable with TTY shows warning",
			args: []string{"install", "."},
			managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) {
				em.InstallLocalFunc = func(dir string) error {
					return &ErrExtensionExecutableNotFound{
						Dir:  tempDir,
						Name: "gh-test",
					}
				}
				em.ListFunc = func() []extensions.Extension {
					return []extensions.Extension{}
				}
				return nil
			},
			wantStderr: fmt.Sprintf(
				"! %s",
				(&ErrExtensionExecutableNotFound{
					Dir:  tempDir,
					Name: "gh-test",
				}).Error()),
			wantErr: false,
			isTTY:   true,
		},
		{
			name: "install local extension without executable with no TTY shows no warning",
			args: []string{"install", "."},
			managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) {
				em.InstallLocalFunc = func(dir string) error {
					return &ErrExtensionExecutableNotFound{
						Dir:  tempDir,
						Name: "gh-test",
					}
				}
				em.ListFunc = func() []extensions.Extension {
					return []extensions.Extension{}
				}
				return nil
			},
			wantStderr: "",
			wantErr:    false,
			isTTY:      false,

Review comment (suggestion):
I would like for this test to be checking the hardcoded string directly, rather than relying on the implementation detail of `Error()`. This way, we have confidence that if the returned value from `Error()` was changed, something would tell us.

Code after:
					return nil
				}
				return func(t *testing.T) {
					calls := em.InstallLocalCalls()
					assert.Equal(t, 1, len(calls))
					assert.Equal(t, localExtensionTempDir, normalizeDir(calls[0].Dir))
				}
			},
		},
		{
			name: "installing local extension without executable with TTY shows warning",
			args: []string{"install", "."},
			managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) {
				em.InstallLocalFunc = func(dir string) error {
					return &ErrExtensionExecutableNotFound{
						Dir:  tempDir,
						Name: "gh-test",
					}
				}
				em.ListFunc = func() []extensions.Extension {
					return []extensions.Extension{}
				}
				return nil
			},
			wantStderr: fmt.Sprintf("! an extension has been installed but there is no executable: executable file named \"%s\" in %s is required to run the extension after install. Perhaps you need to build it?\n", "gh-test", tempDir),
			wantErr:    false,
			isTTY:      true,
		},
		{
			name: "install local extension without executable with no TTY shows no warning",
			args: []string{"install", "."},
			managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) {
				em.InstallLocalFunc = func(dir string) error {
					return &ErrExtensionExecutableNotFound{
						Dir:  tempDir,
						Name: "gh-test",
					}
				}
				em.ListFunc = func() []extensions.Extension {
					return []extensions.Extension{}
				}
				return nil
			},
			wantStderr: "",
			wantErr:    false,
			isTTY:      false,
		},
		{
			name: "error extension not found",
			args: []string{"install", "owner/gh-some-ext"},
			managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) {