ginkgo
Python service microframework
Ginkgo Service Framework — Ginkgo 0.6.0 documentation
I have inherited a Go project that consists of a lot of common files, a library of sorts, two executables, and theoretically a test suite. The test suite is being written after the fact. But I dislike the only way I've found of setting up is rather unpalatable
I'm using Ginkgo, and this is my starting directory structure
- component1/component1.go
- component2/component2.go
- cmd1/cmd1.go
- cmd2/cmd2.go
- project_suite_test.go
- component1_test.go
Each cmd?.go file will be compiled into a separate executable.
What I would like is a multi-file test suite, usually one file per component. Where do I put the files so that go test
will find and run all of them, without leaving them here in the root of the project?
Source: (StackOverflow)
I have some go tests that I would like to update to use Ginkgo for BDD style testing. The problem is, the server uses stdout and stderr for logging, and many of the tests utilize Go's built in "Example" testing framework as follows:
import (
"fmt"
)
func ExampleConsoleLog() {
fmt.Printf("Testing %d, %d, %d: %s\n", 1, 2, 3, "mike check")
// Output:
// Testing 1, 2, 3: mike check
}
I would like to using Ginkgo and Gomega to assert that these get printed out to the stdout, but there are no built in matchers that I can tell that do this. Gomega does provide a gbytes
package, but there is no documentation on how to "attach" a gbytes.Buffer to stdout or stderr. Is there is a custom matcher that I can use for this?
Source: (StackOverflow)
I'm having some success using Ginkgo with goapp test
. However, the recurrent INFO
and WARNING
messages issued by the development server clutter up the terminal a bit much for my liking. The following is repeated for each spec:
INFO 2015-06-02 22:28:50,805 devappserver2.py:726] Skipping SDK update check.
WARNING 2015-06-02 22:28:50,805 devappserver2.py:742] DEFAULT_VERSION_HOSTNAME will not be set correctly with --port=0
WARNING 2015-06-02 22:28:50,857 simple_search_stub.py:1126] Could not read search indexes from /tmp/appengine.testapp.basie/search_indexes
INFO 2015-06-02 22:28:50,859 api_server.py:172] Starting API server at: http://localhost:44696
WARNING 2015-06-02 22:28:50,860 inotify_file_watcher.py:196] There are too many directories in your application for changes in all of them to be monitored. You may have to restart the development server to see some changes to your files.
WARNING 2015-06-02 22:28:50,861 inotify_file_watcher.py:196] There are too many directories in your application for changes in all of them to be monitored. You may have to restart the development server to see some changes to your files.
INFO 2015-06-02 22:28:50,861 dispatcher.py:186] Starting module "default" running at: http://localhost:38301
INFO 2015-06-02 22:28:50,861 admin_server.py:118] Starting admin server at: http://localhost:46337
I'm aware that dev_appserver.py
has a flag to set log level, but I'm drawing a blank on how to make goapp test
understand that, so each test run is accompanied by pages of distracting spam before I get to Ginkgo's output.
I don't see anything to set log level in Ginkgo's own flags. Can anyone point me in the right direction? Alternatively, does the above output suggest I have configured something poorly that should be corrected?
Source: (StackOverflow)
First of all I want to tell you that I’m very new at go and that I came from Python. Having saying that than I can continue with my problem. I’m having the following trouble:
cacciald@cacciald-Lenovo-G470:~/workspace/gopath/src/github.com/lcacciagioni/bosh_web_console/executor$ go test
Running Suite: Executor Suite
=============================
Random Seed: 1409854483
Will run 1 of 1 specs
• Failure [0.005 seconds]
Executor
/home/cacciald/workspace/gopath/src/github.com/lcacciagioni/bosh_web_console/executor/executor_test.go:21
Should execute a command [It]
/home/cacciald/workspace/gopath/src/github.com/lcacciagioni/bosh_web_console/executor/executor_test.go:20
Expected
<string>: Hello World
to be equivalent to
<string>: Hello World
/home/cacciald/workspace/gopath/src/github.com/lcacciagioni/bosh_web_console/executor/executor_test.go:19
------------------------------
Summarizing 1 Failure:
[Fail] Executor [It] Should execute a command
/home/cacciald/workspace/gopath/src/github.com/lcacciagioni/bosh_web_console/executor/executor_test.go:19
Ran 1 of 1 Specs in 0.006 seconds
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped --- FAIL: TestExecutor (0.01 seconds)
FAIL
exit status 1
FAIL github.com/lcacciagioni/bosh_web_console/executor 0.019s
Here is the code:
// Package executor will provide a way to execute console commands in our
// Operative System.-
package executor
import (
"bytes"
"log"
"os/exec"
)
func Runner(command, params string) string {
cmd := exec.Command(command, params)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
return out.String()
}
And here is my simple test:
package executor_test
import (
. "github.com/lcacciagioni/bosh_web_console/executor"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Executor", func() {
var (
cmd string
params string
)
It("Should execute a command", func() {
cmd = "echo"
params = "Hello World"
Expect(Runner(cmd, params)).To(BeEquivalentTo(params))
})
})
If some can tell me why this is not working that will be great!!!
Source: (StackOverflow)
I'm very new to Go, so I may be misunderstanding something foundational about Go's async/stream handling, but here goes...
I'm trying to write some tests using ginkgo on a function I wrote that processes streams.
The processing side reads in newline-delimited text from a File until it encounters a special delimiter line at which point it tries to parse the text as JSON. The code looks like this:
func ParseConfig(inStream *os.File) (Config, error){
var header string
var stdin = bufio.NewScanner(inStream)
for stdin.Scan() {
line := stdin.Text()
if line == "|||" {
break;
}
header += line
}
// parse JSON here and return
}
My test looks something like this
Describe("ParseConfig()", func() {
It("should pass for a valid header", func(){
_, err := io.WriteString(stream, "{\"Key\": \"key\", \"File\": \"file\"}\n|||\n")
Expect(err).NotTo(HaveOccurred())
conf, err := parser.ParseConfig(stream)
Expect(err).NotTo(HaveOccurred())
Expect(conf.Key).To(Equal("key"))
})
})
Unfortunately, this yields a JSON parsing error, as it's trying to parse an empty string. I'm assuming that my problem is that I'm sending the string on the stream before I've told the ParseConfig() function to listen on that string for data? But I'm not entirely clear how I could refactor this to use proper go routines to first listen for data then send it.
Some of the potential solutions I saw were around the use of "channels" (with which I'm unfamiliar) but I was worried that this one need might not be worth a major refactor to introduce a whole new paradigm of concurrency.
Thanks!
Source: (StackOverflow)
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"))
})
})
Source: (StackOverflow)