better testing of the help printing on CLIs
This commit is contained in:
parent
109be6b5e3
commit
f21db281c2
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"cgl.tideland.biz/asserts"
|
"cgl.tideland.biz/asserts"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -63,9 +64,21 @@ func TestEnvironment_DefaultCli_Help(t *testing.T) {
|
||||||
|
|
||||||
defaultEnv := testEnvironment()
|
defaultEnv := testEnvironment()
|
||||||
|
|
||||||
// Test the basic version options
|
// A little lambda to help us test the output actually contains help
|
||||||
|
testOutput := func() {
|
||||||
|
buffer := defaultEnv.Ui().(*ReaderWriterUi).Writer.(*bytes.Buffer)
|
||||||
|
output := buffer.String()
|
||||||
|
buffer.Reset()
|
||||||
|
assert.True(strings.Contains(output, "usage: packer"), "should print help")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test "--help"
|
||||||
assert.Equal(defaultEnv.Cli([]string{"--help"}), 1, "--help should print")
|
assert.Equal(defaultEnv.Cli([]string{"--help"}), 1, "--help should print")
|
||||||
|
testOutput()
|
||||||
|
|
||||||
|
// Test "-h"
|
||||||
assert.Equal(defaultEnv.Cli([]string{"-h"}), 1, "--help should print")
|
assert.Equal(defaultEnv.Cli([]string{"-h"}), 1, "--help should print")
|
||||||
|
testOutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnvironment_DefaultCli_Version(t *testing.T) {
|
func TestEnvironment_DefaultCli_Version(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue