Skip to content

Commit 1597fa3

Browse files
authored
misc: Improve test coverage of main.go and cli.go part.1 (#228)
* Extract initializeSystemVariables * Add test for main * Extract ValidateSpannerOptions * Remove unused DecodeColumn * Improve cli_test.go * Modify confirm to improve testability * Improve coverage
1 parent f5e5b93 commit 1597fa3

4 files changed

Lines changed: 411 additions & 11 deletions

File tree

cli.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (c *Cli) handleSpecialStatements(stmt Statement) (exitCode int, processed b
180180
return -1, true
181181
}
182182

183-
if !confirm(c.OutStream, fmt.Sprintf("Database %q will be dropped.\nDo you want to continue?", s.DatabaseId)) {
183+
if !confirm(c.InStream, c.OutStream, fmt.Sprintf("Database %q will be dropped.\nDo you want to continue?", s.DatabaseId)) {
184184
return -1, true
185185
}
186186
}
@@ -380,10 +380,10 @@ func (c *Cli) getInterpolatedPrompt(prompt string) string {
380380
})
381381
}
382382

383-
func confirm(out io.Writer, msg string) bool {
383+
func confirm(in io.Reader, out io.Writer, msg string) bool {
384384
fmt.Fprintf(out, "%s [yes/no] ", msg)
385385

386-
s := bufio.NewScanner(os.Stdin)
386+
s := bufio.NewScanner(in)
387387
for {
388388
s.Scan()
389389
switch strings.ToLower(s.Text()) {

0 commit comments

Comments
 (0)