goconvey
goconvey copied to clipboard
Output out of order
I'm using goconvey 1.6.3 and i'm getting the output messages out of order, some times they are like this, which is correct:
=== RUN TestResourceCreate
Given a list of resource repositories
With the memory repository
It should be possible to insert a resource with id 1 ✔
It should not be possible to insert another resource with id 1 ✔✔✔
It should not be possible to insert a resource with the same address 0 ✔✔✔
It should not be possible to insert a resource with the same address 1 ✔✔✔
With the mongodb repository
It should be possible to insert a resource with id 1 ✔
It should not be possible to insert another resource with id 1 ✔✔✔
It should not be possible to insert a resource with the same address 0 ✔✔✔
It should not be possible to insert a resource with the same address 1 ✔✔✔
And other times like this:
=== RUN TestResourceCreate
Given a list of resource repositories
With the mongodb repository
It should be possible to insert a resource with id 1 ✔
With the memory repository
It should be possible to insert a resource with id 1 ✔
It should not be possible to insert another resource with id 1 ✔✔✔
It should not be possible to insert a resource with the same address 0 ✔✔✔
It should not be possible to insert a resource with the same address 1 ✔✔✔
It should not be possible to insert another resource with id 1 ✔✔✔
It should not be possible to insert a resource with the same address 0 ✔✔✔
It should not be possible to insert a resource with the same address 1 ✔✔✔
And this is the test:
Convey("Given a list of resource repositories", t, func() {
for name, repository := range repositories {
Convey(fmt.Sprintf("With the %s repository", name), func() {
Convey("It should be possible to insert a resource with id 1", func() {
err := repository.Create(context.Background(), &flare.Resource{
ID: "1",
Addresses: []string{"http://app.com"},
Path: "/users/{*}",
})
So(err, ShouldBeNil)
})
Convey("It should not be possible to insert another resource with id 1", func() {
err := repository.Create(context.Background(), &flare.Resource{
ID: "1",
Addresses: []string{"http://app.com"},
Path: "/sample/{*}",
})
So(err, ShouldNotBeNil)
nErr, ok := err.(flare.ResourceRepositoryError)
So(ok, ShouldBeTrue)
So(nErr.AlreadyExists(), ShouldBeTrue)
})
for i, wildcard := range []string{"id", "*"} {
msg := fmt.Sprintf(
"It should not be possible to insert a resource with the same address %d", i,
)
Convey(msg, func() {
err := repository.Create(context.Background(), &flare.Resource{
ID: "2",
Addresses: []string{"http://app.com"},
Path: fmt.Sprintf("/users/{%s}", wildcard),
})
So(err, ShouldNotBeNil)
nErr, ok := err.(flare.ResourceRepositoryError)
So(ok, ShouldBeTrue)
So(nErr.AlreadyExists(), ShouldBeTrue)
})
}
})
}
})
Am i missing anything?
I had the exact same issue and I resolved it by changing my loop over a map to a loop over a slice of two-field structs. I am guessing that GoConvey somehow relies on Conveys being encountered in a deterministic order, and as such, map iteration order being unspecified and (in the implementation) non-deterministic is causing this behaviour.
For reference:
The iteration order over maps is not specified and is not guaranteed to be the same from one iteration to the next.
(source)