MCPcopy Create free account
hub / github.com/ddev/ddev / TestGetInput

Function TestGetInput

pkg/util/utils_test.go:36–66  ·  view source on GitHub ↗

TestGetInput tests GetInput and Prompt()

(t *testing.T)

Source from the content-addressed store, hash-verified

34
35// TestGetInput tests GetInput and Prompt()
36func TestGetInput(t *testing.T) {
37 assert := asrt.New(t)
38
39 // Try basic GetInput
40 input := "InputIWantToSee"
41 restoreOutput := util.CaptureUserOut()
42 scanner := bufio.NewScanner(strings.NewReader(input))
43 util.SetInputScanner(scanner)
44 result := util.GetInput("nodefault")
45 assert.EqualValues(input, result)
46 _ = restoreOutput()
47
48 // Try Prompt() with a default value which is overridden
49 input = "InputIWantToSee"
50 restoreOutput = util.CaptureUserOut()
51 scanner = bufio.NewScanner(strings.NewReader(input))
52 util.SetInputScanner(scanner)
53 result = util.Prompt("nodefault", "expected default")
54 assert.EqualValues(input, result)
55 _ = restoreOutput()
56
57 // Try Prompt() with a default value but don't provide a response
58 input = ""
59 restoreOutput = util.CaptureUserOut()
60 scanner = bufio.NewScanner(strings.NewReader(input))
61 util.SetInputScanner(scanner)
62 result = util.Prompt("nodefault", "expected default")
63 assert.EqualValues("expected default", result)
64 _ = restoreOutput()
65 println() // Just lets goland find the PASS or FAIL
66}
67
68// TestGetQuotedInput tests GetQuotedInput
69func TestGetQuotedInput(t *testing.T) {

Callers

nothing calls this directly

Calls 4

CaptureUserOutFunction · 0.92
SetInputScannerFunction · 0.92
GetInputFunction · 0.92
PromptFunction · 0.92

Tested by

no test coverage detected