here I am making my first steps in go trying to do BDD on a go command line app. I am using Ginkgo, which wraps testing.go and lets you do more expressive BDD. https://github.com/onsi/ginkgo
I am having issues in reading the stdout to do an assertion on it.
Found that on pkg/testing
example do stub the output before running but I can not find the way to read that output: http://golang.org/src/pkg/testing/example.go
This is what I would like to do:
cli.go
package cli
import "fmt"
func Run() {
fmt.Println("Running cli")
}
cli_test.go
package cli_test
import (
. "github.com/altoros/bosh_deployer_cli/lib/cli"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Cli", func() {
It("should parse update stemcell flag", func() {
Run()
Expect(stdout).To(Equal("running cli"))
})
})
Testing Stdout can be tricky. You have multiple choice.
You can override os.Stdout during your test: (think to check the errors)
or you can pass a writer to your function:
cli.go
cli_test.go
main.go