Skip to content

Commit

Permalink
Perform suite before/after once, not per-test
Browse files Browse the repository at this point in the history
The spec library has a different operation model from Ginkgo. For
one-time before/afters, the logic must sit outside of the spec.Run()
method, not under a it.Before/it.After.

Shows a dramatic speedup, as we are no longer unwittingly recompiling
the command for every single test.

[#4]

Signed-off-by: Jacques Chester <jchester@pivotal.io>
  • Loading branch information
jchester authored and jchesterpivotal committed Aug 18, 2018
1 parent 6dab65d commit fb7b35a
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions cmd/build-pass-fail/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,24 @@ import (
)

func TestBuildPassFail(t *testing.T) {
spec.Run(t, "build-pass-fail", func(t *testing.T, when spec.G, it spec.S) {
var compiledPath string
var err error
var session *gexec.Session
var compiledPath string
var err error
var session *gexec.Session
var gt *gomega.GomegaWithT

gt := gomega.NewGomegaWithT(t)
gt = gomega.NewGomegaWithT(t)

it.Before(func() {
compiledPath, err = gexec.Build("github.com/jchesterpivotal/concourse-build-resource/cmd/build-pass-fail")
if err != nil {
gt.Expect(err).NotTo(gomega.HaveOccurred())
}
compiledPath, err = gexec.Build("github.com/jchesterpivotal/concourse-build-resource/cmd/build-pass-fail")
if err != nil {
gt.Expect(err).NotTo(gomega.HaveOccurred())
}

err = os.Mkdir("build", os.ModeDir|os.ModePerm)
if err != nil {
gt.Expect(err).NotTo(gomega.MatchError("build: file exists"))
}
})

it.After(func() {
gexec.CleanupBuildArtifacts()

err = os.RemoveAll("build")
gt.Expect(err).NotTo(gomega.HaveOccurred())
})
err = os.Mkdir("build", os.ModeDir|os.ModePerm)
if err != nil {
gt.Expect(err).NotTo(gomega.MatchError("build: file exists"))
}

spec.Run(t, "build-pass-fail", func(t *testing.T, when spec.G, it spec.S) {
when("a path to json file is not given", func() {
when("there is no build/build.json", func() {
it.Before(func() {
Expand Down Expand Up @@ -161,4 +153,9 @@ func TestBuildPassFail(t *testing.T) {
})
})
}, spec.Report(report.Terminal{}))

gexec.CleanupBuildArtifacts()

err = os.RemoveAll("build")
gt.Expect(err).NotTo(gomega.HaveOccurred())
}

0 comments on commit fb7b35a

Please sign in to comment.