Skip to content

Instantly share code, notes, and snippets.

@bithavoc
Created December 11, 2014 16:49
Show Gist options
  • Save bithavoc/d7e892328550118ad1fc to your computer and use it in GitHub Desktop.
Save bithavoc/d7e892328550118ad1fc to your computer and use it in GitHub Desktop.
package main
import (
. "github.com/smartystreets/goconvey/convey"
"sync"
"testing"
)
var mutex sync.Mutex
type useIndexHandler func()
//
// Exclusive Index usage helper.
// use only in root Convey (the ones that starts with testing.T)
//
func useIndex(handle useIndexHandler) {
//TODO: wipe elastic search index
//TODO: feed elastic index
mutex.Lock()
defer mutex.Unlock()
handle()
// ... other stuff to run after every test
}
func Test1(t *testing.T) {
Convey("Given something", t, func() {
useIndex(func() {
// test logic here
So(1, ShouldEqual, 1)
Convey("nested something", func() {
So(2, ShouldEqual, 2)
})
})
})
Convey("Given something else", t, func() {
useIndex(func() {
// test logic here
So(1, ShouldEqual, 1)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment