Skip to content

Commit 6ee46eb

Browse files
committed
Add e2e tests for go api and embedded use
1 parent 9789181 commit 6ee46eb

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

hack/apitest/api_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package apitest
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
8+
"github.com/kubernetes-csi/csi-test/pkg/sanity"
9+
)
10+
11+
func TestMyDriver(t *testing.T) {
12+
fmt.Println("Go API test")
13+
14+
config := &sanity.Config{
15+
TargetPath: os.TempDir() + "/csi",
16+
StagingPath: os.TempDir() + "/csi",
17+
Address: "/tmp/e2e-csi-sanity.sock",
18+
}
19+
20+
sanity.Test(t, config)
21+
}

hack/e2e.sh

+22
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ runTestWithCreds()
3535
fi
3636
}
3737

38+
runTestAPI()
39+
{
40+
CSI_ENDPOINT=$1 ./bin/mock &
41+
local pid=$!
42+
43+
GOCACHE=off go test -v ./hack/apitest/api_test.go; ret=$?
44+
45+
if [ $ret -ne 0 ] ; then
46+
exit $ret
47+
fi
48+
49+
GOCACHE=off go test -v ./hack/embedded/embedded_test.go; ret=$?
50+
kill -9 $pid
51+
52+
if [ $ret -ne 0 ] ; then
53+
exit $ret
54+
fi
55+
}
56+
3857
go build -o bin/mock ./mock || exit 1
3958

4059
cd cmd/csi-sanity
@@ -47,4 +66,7 @@ rm -f $UDS
4766
runTestWithCreds "${UDS}" "${UDS}"
4867
rm -f $UDS
4968

69+
runTestAPI "${UDS}"
70+
rm -f $UDS
71+
5072
exit 0

hack/embedded/embedded_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package embedded
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/kubernetes-csi/csi-test/pkg/sanity"
8+
. "github.com/onsi/ginkgo"
9+
. "github.com/onsi/gomega"
10+
)
11+
12+
func TestMyDriverGinkgo(t *testing.T) {
13+
RegisterFailHandler(Fail)
14+
RunSpecs(t, "CSI Sanity Test Suite")
15+
}
16+
17+
var _ = Describe("MyCSIDriver", func() {
18+
Context("Config A", func() {
19+
config := &sanity.Config{
20+
TargetPath: os.TempDir() + "/csi",
21+
StagingPath: os.TempDir() + "/csi",
22+
Address: "/tmp/e2e-csi-sanity.sock",
23+
}
24+
25+
BeforeEach(func() {})
26+
27+
AfterEach(func() {})
28+
29+
Describe("CSI Driver Test Suite", func() {
30+
sanity.GinkgoTest(config)
31+
})
32+
})
33+
})

pkg/sanity/sanity.go

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func GinkgoTest(reqConfig *Config) {
9595
Config: reqConfig,
9696
}
9797

98+
address = sc.Config.Address
9899
registerTestsInGinkgo(sc)
99100
}
100101

0 commit comments

Comments
 (0)