Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
test/components/*: de-duplicate values
Browse files Browse the repository at this point in the history
timeout and retryInterval were same for most of the components and was
duplicated.

closes: #502
Signed-off-by: knrt10 <kautilya@kinvolk.io>
  • Loading branch information
knrt10 committed Oct 7, 2020
1 parent c01551a commit 584e827
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package awsebscsidriver
import (
"fmt"
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -43,7 +42,7 @@ func TestCSIDriverDeployments(t *testing.T) {
test := test
t.Run(fmt.Sprintf("aws-ebs-csi-driver deployment:%s", test.deployment), func(t *testing.T) {
t.Parallel()
testutil.WaitForDeployment(t, client, namespace, test.deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, test.deployment, testutil.RetryInterval, testutil.Timeout)
})
}
}
3 changes: 1 addition & 2 deletions test/components/cert-manager/cert-manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package certmanager
import (
"fmt"
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -47,7 +46,7 @@ func TestCertManagerDeployments(t *testing.T) {
for _, test := range testCases {
t.Run(fmt.Sprintf("cert-manager deployment:%s", test.deployment), func(t *testing.T) {
t.Parallel()
testutil.WaitForDeployment(t, client, namespace, test.deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, test.deployment, testutil.RetryInterval, testutil.Timeout)
})
}
}
7 changes: 2 additions & 5 deletions test/components/cluster-autoscaler/cluster-autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ package clusterautoscaler

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const (
defaultDeploymentTimeout = 5 * time.Minute
defaultDeploymentProbeInterval = 5 * time.Second
name = "cluster-autoscaler-packet-cluster-autoscaler-chart"
name = "cluster-autoscaler-packet-cluster-autoscaler-chart"
)

func TestClusterAutoscalerDeployments(t *testing.T) {
Expand All @@ -36,6 +33,6 @@ func TestClusterAutoscalerDeployments(t *testing.T) {
t.Run("deployment", func(t *testing.T) {
t.Parallel()

testutil.WaitForDeployment(t, client, "kube-system", name, defaultDeploymentProbeInterval, defaultDeploymentTimeout)
testutil.WaitForDeployment(t, client, "kube-system", name, testutil.RetryInterval, testutil.Timeout)
})
}
5 changes: 2 additions & 3 deletions test/components/contour/contour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package contour

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -31,7 +30,7 @@ func TestEnvoyDaemonset(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDaemonSet(t, client, namespace, daemonset, time.Second*5, time.Minute*5)
testutil.WaitForDaemonSet(t, client, namespace, daemonset, testutil.RetryInterval, testutil.Timeout)
}

func TestContourDeployment(t *testing.T) {
Expand All @@ -41,5 +40,5 @@ func TestContourDeployment(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
}
3 changes: 1 addition & 2 deletions test/components/coredns/coredns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package coredns

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -31,5 +30,5 @@ func TestCoreDNSDeployment(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
}
3 changes: 1 addition & 2 deletions test/components/dex/dex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package dex

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -33,6 +32,6 @@ func TestDexDeployment(t *testing.T) {
t.Parallel()
deployment := "dex"

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
6 changes: 3 additions & 3 deletions test/components/external-dns/external-dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package externaldns

import (
"fmt"
testutil "github.com/kinvolk/lokomotive/test/components/util"
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const namespace = "external-dns"
Expand All @@ -32,6 +32,6 @@ func TestExternalDNSDeployments(t *testing.T) {
t.Run(fmt.Sprintf("deployment"), func(t *testing.T) {
t.Parallel()
deployment := "external-dns"
testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
5 changes: 2 additions & 3 deletions test/components/flatcar-linux-update-operator/fluo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package fluo

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -31,7 +30,7 @@ func TestUpdateAgentDaemonset(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDaemonSet(t, client, namespace, daemonset, time.Second*5, time.Minute*5)
testutil.WaitForDaemonSet(t, client, namespace, daemonset, testutil.RetryInterval, testutil.Timeout)
}

func TestUpdateOperatorDeployment(t *testing.T) {
Expand All @@ -41,5 +40,5 @@ func TestUpdateOperatorDeployment(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
}
3 changes: 1 addition & 2 deletions test/components/gangway/gangway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package gangway

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -33,6 +32,6 @@ func TestGangwayDeployment(t *testing.T) {
t.Parallel()
deployment := "gangway"

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
8 changes: 1 addition & 7 deletions test/components/httpbin/httpbin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,16 @@ package httpbin
import (
"fmt"
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const (
defaultDeploymentTimeout = 5 * time.Minute
defaultDeploymentProbeInterval = 5 * time.Second
)

func TestHttpbinDeployments(t *testing.T) {
client := testutil.CreateKubeClient(t)

t.Run(fmt.Sprintf("deployment"), func(t *testing.T) {
t.Parallel()

testutil.WaitForDeployment(t, client, "httpbin", "httpbin", defaultDeploymentProbeInterval, defaultDeploymentTimeout)
testutil.WaitForDeployment(t, client, "httpbin", "httpbin", testutil.RetryInterval, testutil.Timeout)
})
}
2 changes: 1 addition & 1 deletion test/components/kubernetes/controller-manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ func TestControllerManagerDeployment(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDeployment(t, client, namespace, deployment, retryInterval, timeout)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
}
5 changes: 1 addition & 4 deletions test/components/kubernetes/kubelet_disruptive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package kubernetes
import (
"context"
"testing"
"time"

k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -49,10 +48,8 @@ func TestSelfHostedKubeletLabels(t *testing.T) {
t.Errorf("could not delete the node %s: %v", chosenNode, err)
}

retryInterval := time.Second * 5
timeout := time.Minute * 5
// Wait for the node to come up.
if err = wait.PollImmediate(retryInterval, timeout, func() (done bool, err error) {
if err = wait.PollImmediate(testutil.RetryInterval, testutil.Timeout, func() (done bool, err error) {
node, err := client.CoreV1().Nodes().Get(context.TODO(), chosenNode, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
Expand Down
7 changes: 1 addition & 6 deletions test/components/kubernetes/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ package kubernetes

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const retryInterval = time.Second * 5

const timeout = time.Minute * 5

func TestSelfHostedKubeletPods(t *testing.T) {
t.Parallel()

Expand All @@ -36,5 +31,5 @@ func TestSelfHostedKubeletPods(t *testing.T) {
namespace := "kube-system"
daemonset := "kubelet"

testutil.WaitForDaemonSet(t, client, namespace, daemonset, retryInterval, timeout)
testutil.WaitForDaemonSet(t, client, namespace, daemonset, testutil.RetryInterval, testutil.Timeout)
}
5 changes: 2 additions & 3 deletions test/components/metallb/metallb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package metallb

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -33,13 +32,13 @@ func TestMetalLBDeployment(t *testing.T) {
t.Parallel()
daemonset := "speaker"

testutil.WaitForDaemonSet(t, client, namespace, daemonset, time.Second*5, time.Minute*5)
testutil.WaitForDaemonSet(t, client, namespace, daemonset, testutil.RetryInterval, testutil.Timeout)
})

t.Run("controller deployment", func(t *testing.T) {
t.Parallel()
deployment := "controller"

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
3 changes: 1 addition & 2 deletions test/components/metrics-server/metrics_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package metricsserver

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -33,6 +32,6 @@ func TestMetricsServerDeployment(t *testing.T) {
t.Parallel()
deployment := "metrics-server"

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
3 changes: 1 addition & 2 deletions test/components/openebs-operator/openebs_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package openebsoperator

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -42,7 +41,7 @@ func TestOpenEBSOperatorDeployment(t *testing.T) {
t.Run("deployment", func(t *testing.T) {
t.Parallel()

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
}
3 changes: 1 addition & 2 deletions test/components/rook/rook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package rook

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -33,6 +32,6 @@ func TestRookDeployment(t *testing.T) {
t.Parallel()
deployment := "rook-ceph-operator"

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
7 changes: 7 additions & 0 deletions test/components/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ import (
"k8s.io/client-go/transport/spdy"
)

const (
// RetryInterval is time for test to retry.
RetryInterval = time.Second * 5
// Timeout is time after which tests stops and fails.
Timeout = time.Minute * 5
)

func KubeconfigPath(t *testing.T) string {
kubeconfig := os.ExpandEnv(os.Getenv("KUBECONFIG"))

Expand Down

0 comments on commit 584e827

Please sign in to comment.