TestGetInput tests GetInput and Prompt()
(t *testing.T)
| 34 | |
| 35 | // TestGetInput tests GetInput and Prompt() |
| 36 | func 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 |
| 69 | func TestGetQuotedInput(t *testing.T) { |
nothing calls this directly
no test coverage detected