From 9d73de45a4a831b9eeb1c14b3ac9008b3c9594a4 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Mon, 17 Sep 2018 11:39:36 -0700 Subject: [PATCH] Update santiy test to use ginkgo. This have several benefits that: 1. Using consistent testing framework as e2e test 2. Able to define multiple test configurations per: https://github.com/kubernetes-csi/csi-test/tree/master/pkg/sanity 3. Test results will be print to stdout as test runs as opposes to stuck for a while and dump all results at once in the old way --- tests/sanity/sanity_test.go | 45 ++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/tests/sanity/sanity_test.go b/tests/sanity/sanity_test.go index 01a72e5bf0..b70d756355 100644 --- a/tests/sanity/sanity_test.go +++ b/tests/sanity/sanity_test.go @@ -20,12 +20,20 @@ import ( "os" "testing" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/bertinatto/ebs-csi-driver/pkg/cloud" "github.com/bertinatto/ebs-csi-driver/pkg/driver" sanity "github.com/kubernetes-csi/csi-test/pkg/sanity" ) func TestSanity(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "AWS EBS CSI Driver Sanity Tests") +} + +var _ = Describe("AWS EBS CSI Driver", func() { const ( mountPath = "/tmp/csi/mount" stagePath = "/tmp/csi/stage" @@ -33,24 +41,31 @@ func TestSanity(t *testing.T) { endpoint = "unix://" + socket ) - if err := os.Remove(socket); err != nil && !os.IsNotExist(err) { - t.Fatalf("could not remove socket file %s: %v", socket, err) - } - - ebsDriver := driver.NewDriver(cloud.NewFakeCloudProvider(), driver.NewFakeMounter(), endpoint) - defer ebsDriver.Stop() - - go func() { - if err := ebsDriver.Run(); err != nil { - t.Fatalf("could not run CSI driver: %v", err) - } - }() - config := &sanity.Config{ Address: endpoint, TargetPath: mountPath, StagingPath: stagePath, } - sanity.Test(t, config) -} + var ebsDriver *driver.Driver + + BeforeEach(func() { + ebsDriver = driver.NewDriver(cloud.NewFakeCloudProvider(), driver.NewFakeMounter(), endpoint) + go func() { + err := ebsDriver.Run() + Expect(err).To(BeNil()) + }() + }) + + AfterEach(func() { + ebsDriver.Stop() + if err := os.Remove(socket); err != nil && !os.IsNotExist(err) { + Expect(err).To(BeNil()) + } + }) + + Describe("Sanity Test", func() { + sanity.GinkgoTest(config) + }) + +})