prompter

package
v2.49.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertOptions added in v2.21.0

func AssertOptions(t *testing.T, expected, actual []string)

func IndexFor

func IndexFor(options []string, answer string) (int, error)

func NoSuchAnswerErr

func NoSuchAnswerErr(answer string, options []string) error

func NoSuchPromptErr

func NoSuchPromptErr(prompt string) error

Types

type MockPrompter added in v2.25.0

type MockPrompter struct {
	ghPrompter.PrompterMock
	// contains filtered or unexported fields
}

func NewMockPrompter added in v2.25.0

func NewMockPrompter(t *testing.T) *MockPrompter

func (*MockPrompter) AuthToken added in v2.34.0

func (m *MockPrompter) AuthToken() (string, error)

func (*MockPrompter) ConfirmDeletion added in v2.34.0

func (m *MockPrompter) ConfirmDeletion(prompt string) error

func (*MockPrompter) InputHostname added in v2.34.0

func (m *MockPrompter) InputHostname() (string, error)

func (*MockPrompter) MarkdownEditor added in v2.34.0

func (m *MockPrompter) MarkdownEditor(prompt, defaultValue string, blankAllowed bool) (string, error)

func (*MockPrompter) RegisterAuthToken added in v2.34.0

func (m *MockPrompter) RegisterAuthToken(stub func() (string, error))

func (*MockPrompter) RegisterConfirmDeletion added in v2.25.0

func (m *MockPrompter) RegisterConfirmDeletion(prompt string, stub func(string) error)

func (*MockPrompter) RegisterInputHostname added in v2.25.0

func (m *MockPrompter) RegisterInputHostname(stub func() (string, error))

func (*MockPrompter) RegisterMarkdownEditor added in v2.34.0

func (m *MockPrompter) RegisterMarkdownEditor(prompt string, stub func(string, string, bool) (string, error))

func (*MockPrompter) Verify added in v2.25.0

func (m *MockPrompter) Verify()

type Prompter

type Prompter interface {
	// generic prompts from go-gh
	Select(string, string, []string) (int, error)
	MultiSelect(prompt string, defaults []string, options []string) ([]int, error)
	Input(string, string) (string, error)
	Password(string) (string, error)
	Confirm(string, bool) (bool, error)

	// gh specific prompts
	AuthToken() (string, error)
	ConfirmDeletion(string) error
	InputHostname() (string, error)
	MarkdownEditor(string, string, bool) (string, error)
}

func New

func New(editorCmd string, stdin ghPrompter.FileReader, stdout ghPrompter.FileWriter, stderr ghPrompter.FileWriter) Prompter

type PrompterMock

type PrompterMock struct {
	// AuthTokenFunc mocks the AuthToken method.
	AuthTokenFunc func() (string, error)

	// ConfirmFunc mocks the Confirm method.
	ConfirmFunc func(s string, b bool) (bool, error)

	// ConfirmDeletionFunc mocks the ConfirmDeletion method.
	ConfirmDeletionFunc func(s string) error

	// InputFunc mocks the Input method.
	InputFunc func(s1 string, s2 string) (string, error)

	// InputHostnameFunc mocks the InputHostname method.
	InputHostnameFunc func() (string, error)

	// MarkdownEditorFunc mocks the MarkdownEditor method.
	MarkdownEditorFunc func(s1 string, s2 string, b bool) (string, error)

	// MultiSelectFunc mocks the MultiSelect method.
	MultiSelectFunc func(prompt string, defaults []string, options []string) ([]int, error)

	// PasswordFunc mocks the Password method.
	PasswordFunc func(s string) (string, error)

	// SelectFunc mocks the Select method.
	SelectFunc func(s1 string, s2 string, strings []string) (int, error)
	// contains filtered or unexported fields
}

PrompterMock is a mock implementation of Prompter.

func TestSomethingThatUsesPrompter(t *testing.T) {

	// make and configure a mocked Prompter
	mockedPrompter := &PrompterMock{
		AuthTokenFunc: func() (string, error) {
			panic("mock out the AuthToken method")
		},
		ConfirmFunc: func(s string, b bool) (bool, error) {
			panic("mock out the Confirm method")
		},
		ConfirmDeletionFunc: func(s string) error {
			panic("mock out the ConfirmDeletion method")
		},
		InputFunc: func(s1 string, s2 string) (string, error) {
			panic("mock out the Input method")
		},
		InputHostnameFunc: func() (string, error) {
			panic("mock out the InputHostname method")
		},
		MarkdownEditorFunc: func(s1 string, s2 string, b bool) (string, error) {
			panic("mock out the MarkdownEditor method")
		},
		MultiSelectFunc: func(prompt string, defaults []string, options []string) ([]int, error) {
			panic("mock out the MultiSelect method")
		},
		PasswordFunc: func(s string) (string, error) {
			panic("mock out the Password method")
		},
		SelectFunc: func(s1 string, s2 string, strings []string) (int, error) {
			panic("mock out the Select method")
		},
	}

	// use mockedPrompter in code that requires Prompter
	// and then make assertions.

}

func (*PrompterMock) AuthToken

func (mock *PrompterMock) AuthToken() (string, error)

AuthToken calls AuthTokenFunc.

func (*PrompterMock) AuthTokenCalls

func (mock *PrompterMock) AuthTokenCalls() []struct {
}

AuthTokenCalls gets all the calls that were made to AuthToken. Check the length with:

len(mockedPrompter.AuthTokenCalls())

func (*PrompterMock) Confirm

func (mock *PrompterMock) Confirm(s string, b bool) (bool, error)

Confirm calls ConfirmFunc.

func (*PrompterMock) ConfirmCalls

func (mock *PrompterMock) ConfirmCalls() []struct {
	S string
	B bool
}

ConfirmCalls gets all the calls that were made to Confirm. Check the length with:

len(mockedPrompter.ConfirmCalls())

func (*PrompterMock) ConfirmDeletion added in v2.17.0

func (mock *PrompterMock) ConfirmDeletion(s string) error

ConfirmDeletion calls ConfirmDeletionFunc.

func (*PrompterMock) ConfirmDeletionCalls added in v2.17.0

func (mock *PrompterMock) ConfirmDeletionCalls() []struct {
	S string
}

ConfirmDeletionCalls gets all the calls that were made to ConfirmDeletion. Check the length with:

len(mockedPrompter.ConfirmDeletionCalls())

func (*PrompterMock) Input

func (mock *PrompterMock) Input(s1 string, s2 string) (string, error)

Input calls InputFunc.

func (*PrompterMock) InputCalls

func (mock *PrompterMock) InputCalls() []struct {
	S1 string
	S2 string
}

InputCalls gets all the calls that were made to Input. Check the length with:

len(mockedPrompter.InputCalls())

func (*PrompterMock) InputHostname

func (mock *PrompterMock) InputHostname() (string, error)

InputHostname calls InputHostnameFunc.

func (*PrompterMock) InputHostnameCalls

func (mock *PrompterMock) InputHostnameCalls() []struct {
}

InputHostnameCalls gets all the calls that were made to InputHostname. Check the length with:

len(mockedPrompter.InputHostnameCalls())

func (*PrompterMock) MarkdownEditor

func (mock *PrompterMock) MarkdownEditor(s1 string, s2 string, b bool) (string, error)

MarkdownEditor calls MarkdownEditorFunc.

func (*PrompterMock) MarkdownEditorCalls

func (mock *PrompterMock) MarkdownEditorCalls() []struct {
	S1 string
	S2 string
	B  bool
}

MarkdownEditorCalls gets all the calls that were made to MarkdownEditor. Check the length with:

len(mockedPrompter.MarkdownEditorCalls())

func (*PrompterMock) MultiSelect

func (mock *PrompterMock) MultiSelect(prompt string, defaults []string, options []string) ([]int, error)

MultiSelect calls MultiSelectFunc.

func (*PrompterMock) MultiSelectCalls

func (mock *PrompterMock) MultiSelectCalls() []struct {
	Prompt   string
	Defaults []string
	Options  []string
}

MultiSelectCalls gets all the calls that were made to MultiSelect. Check the length with:

len(mockedPrompter.MultiSelectCalls())

func (*PrompterMock) Password

func (mock *PrompterMock) Password(s string) (string, error)

Password calls PasswordFunc.

func (*PrompterMock) PasswordCalls

func (mock *PrompterMock) PasswordCalls() []struct {
	S string
}

PasswordCalls gets all the calls that were made to Password. Check the length with:

len(mockedPrompter.PasswordCalls())

func (*PrompterMock) Select

func (mock *PrompterMock) Select(s1 string, s2 string, strings []string) (int, error)

Select calls SelectFunc.

func (*PrompterMock) SelectCalls

func (mock *PrompterMock) SelectCalls() []struct {
	S1      string
	S2      string
	Strings []string
}

SelectCalls gets all the calls that were made to Select. Check the length with:

len(mockedPrompter.SelectCalls())

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL