Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve readability of test errors; update dependencies; improve test invocation #147

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ test-manifest:
../hack/generate-yaml.sh $(IMAGE_VERSION) > test/manifest/linode-blockstorage-csi-driver.yaml

${GINKGO_PATH}:
go install github.com/onsi/ginkgo/v2/ginkgo@v2.3.1
go install github.com/onsi/ginkgo/v2/ginkgo@v2.13.2

test: ${GINKGO_PATH} check-token test-manifest
go list -m; \
ginkgo -r --v --progress --trace --cover $(TEST_ARGS) -- --v=3 --k8s-version=${K8S_VERSION} $(SUITE_ARGS)
ginkgo -r --vv --procs=6 --trace --cover $(TEST_ARGS) -- --v=3 --k8s-version=${K8S_VERSION} $(SUITE_ARGS)

clean: check-token
cd test; \
Expand Down
24 changes: 12 additions & 12 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module e2e_test
go 1.20

require (
github.com/appscode/go v0.0.0-20190112082056-52eaa8008e2e
github.com/codeskyblue/go-sh v0.0.0-20171228145154-cf804ac79dff
github.com/linode/linodego v1.23.0
github.com/onsi/ginkgo/v2 v2.3.1
github.com/onsi/gomega v1.22.0
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/gomega v1.30.0
github.com/pkg/errors v0.8.0
k8s.io/api v0.0.0-20180904230853-4e7be11eab3f
k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d
Expand All @@ -23,12 +22,14 @@ require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/google/pprof v0.0.0-20231212022811-ec68065c825e // indirect
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect
github.com/imdario/mergo v0.3.7 // indirect
Expand All @@ -37,17 +38,16 @@ require (
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/spf13/pflag v1.0.2 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
golang.org/x/tools v0.16.1 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog v0.3.1 // indirect
sigs.k8s.io/yaml v1.1.0 // indirect
)
109 changes: 28 additions & 81 deletions e2e/go.sum

Large diffs are not rendered by default.

60 changes: 38 additions & 22 deletions e2e/test/csi_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var _ = Describe("Linode CSI Driver", func() {
if err != nil {
return err
}
return f.WaitForReady(pod.ObjectMeta)
return f.IsPodReady(pod.ObjectMeta)
}, f.Timeout, f.RetryInterval).Should(Succeed())

By("Checking that there is a PVC created for the StatefulSet")
Expand Down Expand Up @@ -82,27 +82,33 @@ var _ = Describe("Linode CSI Driver", func() {
}, f.Timeout, f.RetryInterval).Should(Succeed())

By("Waiting for the Volume to be Detached")
Eventually(func() bool {
Eventually(func() error {
isDetached, err := f.IsVolumeDetached(volumeID)
if err != nil {
return false
return err
}
if isDetached {
return nil
}
return isDetached
}, f.Timeout, f.RetryInterval).Should(BeTrue())
return fmt.Errorf("volume %d is still attached", volumeID)
}, f.Timeout, f.RetryInterval).Should(Succeed())

By("Deleting the PVC")
Eventually(func() error {
return f.DeletePersistentVolumeClaim(pvc.ObjectMeta)
}, f.Timeout, f.RetryInterval).Should(Succeed())

By("Waiting for the Volume to be Deleted")
Eventually(func() bool {
Eventually(func() error {
isDeleted, err := f.IsVolumeDeleted(volumeID)
if err != nil {
return false
return err
}
if isDeleted {
return nil
}
return isDeleted
}, f.Timeout, f.RetryInterval).Should(BeTrue())
return fmt.Errorf("volume %d is still present", volumeID)
}, f.Timeout, f.RetryInterval).Should(Succeed())
})

It("Ensures no data is lost between Pod deletions", func() {
Expand Down Expand Up @@ -130,7 +136,7 @@ var _ = Describe("Linode CSI Driver", func() {
return nil
}, f.Timeout, f.RetryInterval).Should(Succeed())
Eventually(func() error {
return f.WaitForReady(pod.ObjectMeta)
return f.IsPodReady(pod.ObjectMeta)
}, f.Timeout, f.RetryInterval).Should(Succeed())

By("Checking that the file is still present inside the container")
Expand Down Expand Up @@ -171,9 +177,12 @@ var _ = Describe("Linode CSI Driver", func() {
Expect(err).NotTo(HaveOccurred())

By("Checking if Volume expansion occurred")
Eventually(func() string {
s, _ := f.GetVolumeSize(currentPVC)
return strconv.Itoa(s) + "Gi"
Eventually(func() (string, error) {
s, err := f.GetVolumeSize(currentPVC)
if err != nil {
return "", err
}
return strconv.Itoa(s) + "Gi", nil
}, f.Timeout, f.RetryInterval).Should(Equal(size))
}
)
Expand All @@ -196,8 +205,9 @@ var _ = Describe("Linode CSI Driver", func() {
pod, err = f.GetPodObject("test-pod"+r, f.Namespace(), pvc.Name, volumeType)
Expect(err).NotTo(HaveOccurred())

Expect(f.CreatePod(pod)).To(Succeed())
Eventually(func() error {
return f.CreatePod(pod)
return f.IsPodReady(pod.ObjectMeta)
}, f.Timeout, f.RetryInterval).Should(Succeed())
})

Expand Down Expand Up @@ -226,27 +236,33 @@ var _ = Describe("Linode CSI Driver", func() {
}, f.Timeout, f.RetryInterval).Should(Succeed())

By("Waiting for the Volume to be Detached")
Eventually(func() bool {
Eventually(func() error {
isDetached, err := f.IsVolumeDetached(volumeID)
if err != nil {
return false
return err
}
return isDetached
}, f.Timeout, f.RetryInterval).Should(BeTrue())
if isDetached {
return nil
}
return fmt.Errorf("volume %d is still attached", volumeID)
}, f.Timeout, f.RetryInterval).Should(Succeed())

By("Deleting the PVC")
Eventually(func() error {
return f.DeletePersistentVolumeClaim(pvc.ObjectMeta)
}, f.Timeout, f.RetryInterval).Should(Succeed())

By("Waiting for the Volume to be Deleted")
Eventually(func() bool {
Eventually(func() error {
isDeleted, err := f.IsVolumeDeleted(volumeID)
if err != nil {
return false
return err
}
return isDeleted
}, f.Timeout, f.RetryInterval).Should(BeTrue())
if isDeleted {
return nil
}
return fmt.Errorf("volume %d is still present", volumeID)
}, f.Timeout, f.RetryInterval).Should(Succeed())
})

// filesystem
Expand Down
5 changes: 3 additions & 2 deletions e2e/test/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package test

import (
"flag"
"fmt"
"math/rand"
"os"
"testing"
"time"

"github.com/appscode/go/crypto/rand"
"k8s.io/client-go/util/homedir"

"github.com/linode/linodego"
Expand Down Expand Up @@ -69,7 +70,7 @@ var _ = BeforeSuite(func() {
if reuse {
clusterName = "csi-linode-for-reuse"
} else {
clusterName = rand.WithUniqSuffix("csi-linode")
clusterName = fmt.Sprintf("csi-linode-%x", rand.Int31())
}

dir, err := os.Getwd()
Expand Down
6 changes: 3 additions & 3 deletions e2e/test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package framework

import (
"fmt"
"math/rand"
"time"

core "k8s.io/api/core/v1"

"github.com/appscode/go/crypto/rand"
"github.com/linode/linodego"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -43,7 +43,7 @@ func New(
linodeClient: linodeClient,

name: "csidriver",
namespace: rand.WithUniqSuffix("csi"),
namespace: fmt.Sprintf("csi-%x", rand.Int31()),
}
}

Expand All @@ -52,7 +52,7 @@ func (f *Framework) Invoke() *Invocation {
Framework: f,
Timeout: Timeout,
RetryInterval: RetryInterval,
app: rand.WithUniqSuffix("csi-driver-e2e"),
app: fmt.Sprintf("csi-driver-e2e-%x", rand.Int31()),
}
}

Expand Down
28 changes: 11 additions & 17 deletions e2e/test/framework/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"strings"

"github.com/appscode/go/wait"
"github.com/pkg/errors"
core "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -62,11 +61,8 @@ func (f *Invocation) GetPodObject(name, namespace, pvc string, volumeType core.P
}

func (f *Invocation) CreatePod(pod *core.Pod) error {
pod, err := f.kubeClient.CoreV1().Pods(pod.ObjectMeta.Namespace).Create(pod)
if err != nil {
return err
}
return f.WaitForReady(pod.ObjectMeta)
_, err := f.kubeClient.CoreV1().Pods(pod.ObjectMeta.Namespace).Create(pod)
return err
}

func (f *Invocation) DeletePod(meta metav1.ObjectMeta) error {
Expand All @@ -81,17 +77,15 @@ func (f *Invocation) GetPod(name, namespace string) (*core.Pod, error) {
return f.kubeClient.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{})
}

func (f *Invocation) WaitForReady(meta metav1.ObjectMeta) error {
return wait.PollImmediate(f.RetryInterval, f.Timeout, func() (bool, error) {
pod, err := f.kubeClient.CoreV1().Pods(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
if pod == nil || err != nil {
return false, nil
}
if pod.Status.Phase == core.PodRunning {
return true, nil
}
return false, nil
})
func (f *Invocation) IsPodReady(meta metav1.ObjectMeta) error {
pod, err := f.kubeClient.CoreV1().Pods(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
if err != nil {
return err
}
if pod.Status.Phase == core.PodRunning {
return nil
}
return fmt.Errorf("pod %s/%s not ready: %v", meta.Namespace, meta.Name, pod.Status.Phase)
}

func (f *Invocation) WriteFileIntoPod(filename string, pod *core.Pod) error {
Expand Down
Loading