prompter

package
v2.0.0-...-98537dd Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexFor

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

func NoSuchAnswerErr

func NoSuchAnswerErr(answer string) error

func NoSuchPromptErr

func NoSuchPromptErr(prompt string) error

Types

type Prompter

type Prompter interface {
	Select(string, string, []string) (int, error)
	MultiSelect(string, string, []string) (int, error)
	Input(string, string) (string, error)
	InputHostname() (string, error)
	Password(string) (string, error)
	AuthToken() (string, error)
	Confirm(string, bool) (bool, error)
	ConfirmDeletion(string) error
	MarkdownEditor(string, string, bool) (string, error)
}

func New

func New(editorCmd string, stdin fileReader, stdout fileWriter, stderr io.Writer) 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(s1 string, s2 string, strings []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(s1 string, s2 string, strings []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

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

ConfirmDeletion calls ConfirmDeletionFunc.

func (*PrompterMock) ConfirmDeletionCalls

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(s1 string, s2 string, strings []string) (int, error)

MultiSelect calls MultiSelectFunc.

func (*PrompterMock) MultiSelectCalls

func (mock *PrompterMock) MultiSelectCalls() []struct {
	S1      string
	S2      string
	Strings []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