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

Function TestGetQuotedInput

pkg/util/utils_test.go:69–92  ·  view source on GitHub ↗

TestGetQuotedInput tests GetQuotedInput

(t *testing.T)

Source from the content-addressed store, hash-verified

67
68// TestGetQuotedInput tests GetQuotedInput
69func TestGetQuotedInput(t *testing.T) {
70 testCases := []struct {
71 description string
72 input string
73 expected string
74 }{
75 {"Remove single quotes", `'/path/to/file'`, `/path/to/file`},
76 {"Remove double quotes", `"/path/to/file"`, `/path/to/file`},
77 {"Remove spaces", ` /path/to/file `, `/path/to/file`},
78 {"Remove all quotes and spaces", ` ''' """ /path/to/file ''' """ `, `/path/to/file`},
79 {"Quotes and spaces are not removed from the middle", `/path/'" to/file`, `/path/'" to/file`},
80 }
81 for _, tc := range testCases {
82 t.Run(tc.description, func(t *testing.T) {
83 assert := asrt.New(t)
84 restoreOutput := util.CaptureUserOut()
85 scanner := bufio.NewScanner(strings.NewReader(tc.input))
86 util.SetInputScanner(scanner)
87 result := util.GetQuotedInput("nodefault")
88 assert.EqualValues(tc.expected, result)
89 _ = restoreOutput()
90 })
91 }
92}
93
94// TestCaptureUserOut ensures capturing of stdout works as expected.
95func TestCaptureUserOut(t *testing.T) {

Callers

nothing calls this directly

Calls 3

CaptureUserOutFunction · 0.92
SetInputScannerFunction · 0.92
GetQuotedInputFunction · 0.92

Tested by

no test coverage detected