github.com/cloudfoundry-incubator/stembuild@v0.0.0-20211223202937-5b61d62226c6/commandparser/help_test.go (about) 1 package commandparser_test 2 3 import ( 4 "bytes" 5 "flag" 6 "fmt" 7 . "github.com/cloudfoundry-incubator/stembuild/commandparser" 8 "github.com/cloudfoundry-incubator/stembuild/version" 9 "github.com/google/subcommands" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 "os" 13 "path" 14 ) 15 16 var _ = Describe("help", func() { 17 // Focus of this test is not to test the Flags.Parse functionality as much 18 // as to test that the command line flags values are stored in the expected 19 // struct variables. This adds a bit of protection when renaming flag parameters. 20 Describe("Explain", func() { 21 It("shows the correct version", func() { 22 version.Version = "1.56" 23 buf := bytes.Buffer{} 24 fs := flag.NewFlagSet(path.Base(os.Args[0]), flag.ExitOnError) 25 commands := make([]subcommands.Command, 0) 26 sb := NewStembuildHelp(subcommands.DefaultCommander, fs, &commands) 27 28 sb.Explain(&buf) 29 30 expectedString := fmt.Sprintf("%s version %s, Windows Stemcell Building Tool", path.Base(os.Args[0]), version.Version) 31 Expect(buf.String()).To(ContainSubstring(expectedString)) 32 }) 33 }) 34 })