Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
test(provisioning): add ginkgo tests for volume provisioning (#28)
Browse files Browse the repository at this point in the history
Signed-off-by: Payes Anand <[email protected]>
  • Loading branch information
payes authored Oct 9, 2020
1 parent 3f11137 commit aa7c091
Show file tree
Hide file tree
Showing 10 changed files with 497 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ script:
- cd ${TRAVIS_BUILD_DIR}
- kubectl apply -f deploy/jiva-csi.yaml
- ./ci/ci.sh
- cd ./tests
- make tests

after_success:
- make push
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ EXTERNAL_TOOLS=\
golang.org/x/tools/cmd/cover \
github.com/axw/gocov/gocov \
github.com/ugorji/go/codec/codecgen \
github.com/onsi/ginkgo/ginkgo \
github.com/onsi/gomega/...

# Lint our code. Reference: https://golang.org/cmd/vet/
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \
Expand All @@ -99,7 +101,7 @@ else
export GIT_TAG
endif

PACKAGES = $(shell go list ./... | grep -v 'vendor')
PACKAGES = $(shell go list ./... | grep -v 'vendor\|tests')

LDFLAGS ?= \
-extldflags "-static" \
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ require (
github.com/container-storage-interface/spec v1.2.0
github.com/kubernetes-csi/csi-lib-iscsi v0.0.0-20191120152119-1430b53a1741
github.com/kubernetes-csi/csi-lib-utils v0.6.1
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
github.com/openebs/jiva-operator v1.12.2-0.20200929135617-d7f7f0d9e81d
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934
google.golang.org/grpc v1.24.0
k8s.io/api v0.17.3
k8s.io/apimachinery v0.17.3
k8s.io/client-go v12.0.0+incompatible
k8s.io/cloud-provider v0.17.3
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw=
cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
github.com/Azure/azure-sdk-for-go v32.5.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go v35.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
Expand Down
38 changes: 38 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright © 2020 The OpenEBS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
GOFLAGS=-mod=vendor
export GOFLAGS
GINKGO=$(GOPATH)/bin/ginkgo
KUBECTL=/usr/local/bin/kubectl


# If you want to change the Kubernetes version for e2e test, specify this variable from command line.
# e.g. $ make TEST_KUBERNETES_VERSION=1.17 test
TEST_KUBERNETES_VERSION=1.17

ifeq ($(TEST_KUBERNETES_VERSION),1.17)
KUBERNETES_VERSION=1.17.2
endif


tests:
env \
PATH=$(PATH) \
GOPATH=$(GOPATH) \
GO111MODULE=on \
GOFLAGS=$(GOFLAGS) \
TEST_KUBERNETES_VERSION=$(TEST_KUBERNETES_VERSION) \
$(GINKGO) --failFast -v .

44 changes: 44 additions & 0 deletions tests/kube_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright © 2020 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package volume

import (
"bytes"
"os/exec"
)

func execAtLocal(cmd string, input []byte, args ...string) ([]byte, []byte, error) {
var stdout, stderr bytes.Buffer
command := exec.Command(cmd, args...)
command.Stdout = &stdout
command.Stderr = &stderr

if len(input) != 0 {
command.Stdin = bytes.NewReader(input)
}

err := command.Run()
return stdout.Bytes(), stderr.Bytes(), err
}

func Kubectl(args ...string) ([]byte, []byte, error) {
return execAtLocal("kubectl", nil, args...)
}

func KubectlWithInput(input []byte, args ...string) ([]byte, []byte, error) {
return execAtLocal("kubectl", input, args...)
}
46 changes: 46 additions & 0 deletions tests/provision_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2020 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package volume

import (
. "github.com/onsi/ginkgo"
)

var _ = Describe("[csi] [jiva] TEST VOLUME PROVISIONING WITH APP POD RESTART", func() {
BeforeEach(prepareForVolumeCreationTest)
AfterEach(cleanupAfterVolumeCreationTest)

Context("App is deployed and restarted on pvc with replica count 1", func() {
It("Should run Volume Creation Test", volumeCreationTest)
})
})

func volumeCreationTest() {
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("Creating and deploying app pod", createDeployVerifyApp)
By("Restarting app pod and verifying app pod running status", restartAppPodAndVerifyRunningStatus)
By("Deleting application deployment", deleteAppDeployment)
By("Deleting pvc", deletePVC)
}

func prepareForVolumeCreationTest() {
By("Creating storage class", createStorageClass)
}

func cleanupAfterVolumeCreationTest() {
By("Deleting storage class", deleteStorageClass)
}
88 changes: 88 additions & 0 deletions tests/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright © 2020 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package volume

import (
"encoding/json"
"errors"
"fmt"
"math/rand"
"testing"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"

// auth plugins
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)

var (
openebsNamespace = "openebs"
)

func TestMtest(t *testing.T) {
// if os.Getenv("E2ETEST") == "" {
// t.Skip("Run under e2e/")
//}
rand.Seed(time.Now().UnixNano())

RegisterFailHandler(Fail)

SetDefaultEventuallyPollingInterval(time.Second)
SetDefaultEventuallyTimeout(time.Minute)

RunSpecs(t, "Test on sanity")
}

func waitKindnet() error {
stdout, stderr, err := Kubectl("-n=kube-system", "get", "ds/kindnet", "-o", "json")
if err != nil {
return errors.New(string(stderr))
}

var ds appsv1.DaemonSet
err = json.Unmarshal(stdout, &ds)
if err != nil {
return err
}

if ds.Status.NumberReady != 4 {
return fmt.Errorf("numberReady is not 4: %d", ds.Status.NumberReady)
}
return nil
}

var _ = BeforeSuite(func() {

var err error

By("creating namespace")
stdout, stderr, err := Kubectl("create", "ns", NSName)
Expect(err).ShouldNot(HaveOccurred(), "stdout=%s, stderr=%s", stdout, stderr)
By("Creating JivaVolumePolicy", createJivaVolumePolicy)

})

var _ = AfterSuite(func() {

By("Deleting JivaVolumePolicy", deleteJivaVolumePolicy)
By("Deleting namespace")
stdout, stderr, err := Kubectl("delete", "ns", NSName)
Expect(err).ShouldNot(HaveOccurred(), "stdout=%s, stderr=%s", stdout, stderr)
})
Loading

0 comments on commit aa7c091

Please sign in to comment.