Documentation
¶
Index ¶
- func AssertOptions(t *testing.T, expected, actual []string)
- func IndexFor(options []string, answer string) (int, error)
- func IndexesFor(options []string, answers ...string) ([]int, error)
- func NoSuchAnswerErr(answer string, options []string) error
- func NoSuchPromptErr(prompt string) error
- type MockPrompter
- func (m *MockPrompter) AuthToken() (string, error)
- func (m *MockPrompter) ConfirmDeletion(prompt string) error
- func (m *MockPrompter) InputHostname() (string, error)
- func (m *MockPrompter) MarkdownEditor(prompt, defaultValue string, blankAllowed bool) (string, error)
- func (m *MockPrompter) RegisterAuthToken(stub func() (string, error))
- func (m *MockPrompter) RegisterConfirmDeletion(prompt string, stub func(string) error)
- func (m *MockPrompter) RegisterInputHostname(stub func() (string, error))
- func (m *MockPrompter) RegisterMarkdownEditor(prompt string, stub func(string, string, bool) (string, error))
- func (m *MockPrompter) Verify()
- type Prompter
- type PrompterMock
- func (mock *PrompterMock) AuthToken() (string, error)
- func (mock *PrompterMock) AuthTokenCalls() []struct{}
- func (mock *PrompterMock) Confirm(prompt string, defaultValue bool) (bool, error)
- func (mock *PrompterMock) ConfirmCalls() []struct{ ... }
- func (mock *PrompterMock) ConfirmDeletion(requiredValue string) error
- func (mock *PrompterMock) ConfirmDeletionCalls() []struct{ ... }
- func (mock *PrompterMock) Input(prompt string, defaultValue string) (string, error)
- func (mock *PrompterMock) InputCalls() []struct{ ... }
- func (mock *PrompterMock) InputHostname() (string, error)
- func (mock *PrompterMock) InputHostnameCalls() []struct{}
- func (mock *PrompterMock) MarkdownEditor(prompt string, defaultValue string, blankAllowed bool) (string, error)
- func (mock *PrompterMock) MarkdownEditorCalls() []struct{ ... }
- func (mock *PrompterMock) MultiSelect(prompt string, defaults []string, options []string) ([]int, error)
- func (mock *PrompterMock) MultiSelectCalls() []struct{ ... }
- func (mock *PrompterMock) Password(prompt string) (string, error)
- func (mock *PrompterMock) PasswordCalls() []struct{ ... }
- func (mock *PrompterMock) Select(prompt string, defaultValue string, options []string) (int, error)
- func (mock *PrompterMock) SelectCalls() []struct{ ... }
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertOptions ¶
func NoSuchAnswerErr ¶
func NoSuchPromptErr ¶
Types ¶
type MockPrompter ¶
type MockPrompter struct {
ghPrompter.PrompterMock
// contains filtered or unexported fields
}
func NewMockPrompter ¶
func NewMockPrompter(t *testing.T) *MockPrompter
func (*MockPrompter) AuthToken ¶
func (m *MockPrompter) AuthToken() (string, error)
func (*MockPrompter) ConfirmDeletion ¶
func (m *MockPrompter) ConfirmDeletion(prompt string) error
func (*MockPrompter) InputHostname ¶
func (m *MockPrompter) InputHostname() (string, error)
func (*MockPrompter) MarkdownEditor ¶
func (m *MockPrompter) MarkdownEditor(prompt, defaultValue string, blankAllowed bool) (string, error)
func (*MockPrompter) RegisterAuthToken ¶
func (m *MockPrompter) RegisterAuthToken(stub func() (string, error))
func (*MockPrompter) RegisterConfirmDeletion ¶
func (m *MockPrompter) RegisterConfirmDeletion(prompt string, stub func(string) error)
func (*MockPrompter) RegisterInputHostname ¶
func (m *MockPrompter) RegisterInputHostname(stub func() (string, error))
func (*MockPrompter) RegisterMarkdownEditor ¶
func (*MockPrompter) Verify ¶
func (m *MockPrompter) Verify()
type Prompter ¶
type Prompter interface {
// Select prompts the user to select an option from a list of options.
Select(prompt string, defaultValue string, options []string) (int, error)
// MultiSelect prompts the user to select one or more options from a list of options.
MultiSelect(prompt string, defaults []string, options []string) ([]int, error)
// Input prompts the user to enter a string value.
Input(prompt string, defaultValue string) (string, error)
// Password prompts the user to enter a password.
Password(prompt string) (string, error)
// Confirm prompts the user to confirm an action.
Confirm(prompt string, defaultValue bool) (bool, error)
// AuthToken prompts the user to enter an authentication token.
AuthToken() (string, error)
// ConfirmDeletion prompts the user to confirm deletion of a resource by
// typing the requiredValue.
ConfirmDeletion(requiredValue string) error
// InputHostname prompts the user to enter a hostname.
InputHostname() (string, error)
// MarkdownEditor prompts the user to edit a markdown document in an editor.
// If blankAllowed is true, the user can skip the editor and an empty string
// will be returned.
MarkdownEditor(prompt string, defaultValue string, blankAllowed bool) (string, error)
}
type PrompterMock ¶
type PrompterMock struct {
// AuthTokenFunc mocks the AuthToken method.
AuthTokenFunc func() (string, error)
// ConfirmFunc mocks the Confirm method.
ConfirmFunc func(prompt string, defaultValue bool) (bool, error)
// ConfirmDeletionFunc mocks the ConfirmDeletion method.
ConfirmDeletionFunc func(requiredValue string) error
// InputFunc mocks the Input method.
InputFunc func(prompt string, defaultValue string) (string, error)
// InputHostnameFunc mocks the InputHostname method.
InputHostnameFunc func() (string, error)
// MarkdownEditorFunc mocks the MarkdownEditor method.
MarkdownEditorFunc func(prompt string, defaultValue string, blankAllowed 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(prompt string) (string, error)
// SelectFunc mocks the Select method.
SelectFunc func(prompt string, defaultValue string, options []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(prompt string, defaultValue bool) (bool, error) {
panic("mock out the Confirm method")
},
ConfirmDeletionFunc: func(requiredValue string) error {
panic("mock out the ConfirmDeletion method")
},
InputFunc: func(prompt string, defaultValue string) (string, error) {
panic("mock out the Input method")
},
InputHostnameFunc: func() (string, error) {
panic("mock out the InputHostname method")
},
MarkdownEditorFunc: func(prompt string, defaultValue string, blankAllowed 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(prompt string) (string, error) {
panic("mock out the Password method")
},
SelectFunc: func(prompt string, defaultValue string, options []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(prompt string, defaultValue bool) (bool, error)
Confirm calls ConfirmFunc.
func (*PrompterMock) ConfirmCalls ¶
func (mock *PrompterMock) ConfirmCalls() []struct { Prompt string DefaultValue bool }
ConfirmCalls gets all the calls that were made to Confirm. Check the length with:
len(mockedPrompter.ConfirmCalls())
func (*PrompterMock) ConfirmDeletion ¶
func (mock *PrompterMock) ConfirmDeletion(requiredValue string) error
ConfirmDeletion calls ConfirmDeletionFunc.
func (*PrompterMock) ConfirmDeletionCalls ¶
func (mock *PrompterMock) ConfirmDeletionCalls() []struct { RequiredValue 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(prompt string, defaultValue string) (string, error)
Input calls InputFunc.
func (*PrompterMock) InputCalls ¶
func (mock *PrompterMock) InputCalls() []struct { Prompt string DefaultValue 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(prompt string, defaultValue string, blankAllowed bool) (string, error)
MarkdownEditor calls MarkdownEditorFunc.
func (*PrompterMock) MarkdownEditorCalls ¶
func (mock *PrompterMock) MarkdownEditorCalls() []struct { Prompt string DefaultValue string BlankAllowed 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(prompt string) (string, error)
Password calls PasswordFunc.
func (*PrompterMock) PasswordCalls ¶
func (mock *PrompterMock) PasswordCalls() []struct { Prompt string }
PasswordCalls gets all the calls that were made to Password. Check the length with:
len(mockedPrompter.PasswordCalls())
func (*PrompterMock) SelectCalls ¶
func (mock *PrompterMock) SelectCalls() []struct { Prompt string DefaultValue string Options []string }
SelectCalls gets all the calls that were made to Select. Check the length with:
len(mockedPrompter.SelectCalls())