Created
January 10, 2019 09:00
-
-
Save lixin9311/91a8ac5d669c254427c5badf5a130a7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dummy | |
import ( | |
"fmt" | |
"os" | |
"os/signal" | |
"syscall" | |
"testing" | |
"time" | |
. "github.com/onsi/ginkgo" | |
"github.com/onsi/gomega" | |
) | |
var ( | |
done = make(chan struct{}) | |
) | |
func TestDummy(t *testing.T) { | |
gomega.RegisterFailHandler(Fail) | |
c := make(chan os.Signal, 1) | |
signal.Notify(c, syscall.SIGQUIT) | |
go func() { | |
defer GinkgoRecover() | |
<-c | |
fmt.Println("captured the signal") | |
close(done) | |
}() | |
RunSpecs(t, "Dummy Suite") | |
} | |
func delay(n int) { | |
for i := 0; i < 10; i++ { | |
time.Sleep(100 * time.Duration(n) * time.Millisecond) | |
fmt.Printf(".") | |
} | |
fmt.Printf("\n") | |
} | |
var _ = Describe("DCM Tests", func() { | |
BeforeSuite(func() { | |
fmt.Printf("[BeforeSuite]: preparing") | |
delay(1) | |
}) | |
AfterSuite(func() { | |
fmt.Printf("[AfterSuite]: cleaning up") | |
delay(5) | |
}) | |
BeforeEach(func() { | |
fmt.Printf("[BeforeEach]: Running test case") | |
delay(1) | |
}) | |
AfterEach(func() { | |
fmt.Printf("[AfterEach]: Finished running test case") | |
delay(5) | |
}) | |
It("dummy test case", func() { | |
fail := make(chan string) | |
go func() { | |
// test code goes here | |
fmt.Printf("step1") | |
delay(5) | |
fmt.Printf("step2") | |
delay(5) | |
fail <- "Some reason" | |
fmt.Printf("last step") | |
delay(5) | |
close(fail) | |
}() | |
select { | |
case <-done: | |
Fail("Manual fail") | |
case reason, ok := <-fail: | |
if ok { | |
Fail(reason) | |
} | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment