| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "bufio" |
| 5 | "io" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | // The wizard used to write 128000 unconditionally, so a 1M-window relay was |
| 11 | // recorded as 128K and compacted at roughly a tenth of its real capacity. |
| 12 | func TestAskContextWindowAcceptsTheRealWindow(t *testing.T) { |
| 13 | for _, tc := range []struct { |
| 14 | name string |
| 15 | input string |
| 16 | want int |
| 17 | }{ |
| 18 | {"explicit large window", "1048576\n", 1048576}, |
| 19 | {"surrounding spaces", " 200000 \n", 200000}, |
| 20 | {"empty keeps the conservative default", "\n", defaultCustomContextWindow}, |
| 21 | {"non-numeric keeps the default", "not-a-number\n", defaultCustomContextWindow}, |
| 22 | {"zero keeps the default", "0\n", defaultCustomContextWindow}, |
| 23 | {"negative keeps the default", "-5\n", defaultCustomContextWindow}, |
| 24 | {"closed input keeps the default", "", defaultCustomContextWindow}, |
| 25 | } { |
| 26 | t.Run(tc.name, func(t *testing.T) { |
| 27 | got := askContextWindow(bufio.NewScanner(strings.NewReader(tc.input)), io.Discard) |
| 28 | if got != tc.want { |
| 29 | t.Errorf("askContextWindow(%q) = %d, want %d", tc.input, got, tc.want) |
| 30 | } |
| 31 | }) |
| 32 | } |
| 33 | } |
| 34 |