From fe3ac95abcccc27118f0ccf9cb41149012d96c24 Mon Sep 17 00:00:00 2001 From: Leonardo Scalabrini Date: Thu, 1 Aug 2024 18:49:10 -0300 Subject: [PATCH]
Convert test_wl_deamonset test to go --- .../actions/workloads/deamonset/deamonset.go | 26 +++++++++++++++++++ .../v2/validation/workloads/workload_test.go | 12 +++++++++ .../validation/tests/v3_api/test_workload.py | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/v2/actions/workloads/deamonset/deamonset.go diff --git a/tests/v2/actions/workloads/deamonset/deamonset.go b/tests/v2/actions/workloads/deamonset/deamonset.go new file mode 100644 index 00000000000..9357f5bb804 --- /dev/null +++ b/tests/v2/actions/workloads/deamonset/deamonset.go @@ -0,0 +1,26 @@ +package deamonset + +import ( + "github.com/rancher/rancher/tests/v2/actions/workloads/deployment" + "github.com/rancher/shepherd/clients/rancher" + "github.com/rancher/shepherd/extensions/charts" + "github.com/rancher/shepherd/extensions/workloads" + appv1 "k8s.io/api/apps/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// CreateDeamonset is a helper to create a deamonset +func CreateDeamonset(client *rancher.Client, clusterID, namespaceName string, replicaCount int, secretName, configMapName string, useEnvVars, useVolumes bool) (*appv1.DaemonSet, error) { + deploymentTemplate, err := deployment.CreateDeployment(client, clusterID, namespaceName, replicaCount, secretName, configMapName, useEnvVars, useVolumes) + if err != nil { + return nil, err + } + + createdDaemonset := workloads.NewDaemonSetTemplate(deploymentTemplate.Name, namespaceName, deploymentTemplate.Spec.Template, true, nil) + + err = charts.WatchAndWaitDaemonSets(client, clusterID, namespaceName, metav1.ListOptions{ + FieldSelector: "metadata.name=" + createdDaemonset.Name, + }) + + return createdDaemonset, err +} diff --git a/tests/v2/validation/workloads/workload_test.go b/tests/v2/validation/workloads/workload_test.go index 70df4f00f77..3bc60b7e08b 100644 --- a/tests/v2/validation/workloads/workload_test.go +++ b/tests/v2/validation/workloads/workload_test.go @@ -4,6 +4,7 @@ import ( "testing" projectsapi "github.com/rancher/rancher/tests/v2/actions/projects" + "github.com/rancher/rancher/tests/v2/actions/workloads/deamonset" deployment "github.com/rancher/rancher/tests/v2/actions/workloads/deployment" "github.com/rancher/rancher/tests/v2/actions/workloads/pods" "github.com/rancher/shepherd/clients/rancher" @@ -94,6 +95,17 @@ func (w *WorkloadTestSuite) TestWorkloadSideKick() { require.Equal(w.T(), 2, countRunning) } +func (w *WorkloadTestSuite) TestWorkloadDaemonSet() { + subSession := w.session.NewSession() + defer subSession.Cleanup() + + _, namespace, err := projectsapi.CreateProjectAndNamespace(w.client, w.cluster.ID) + require.NoError(w.T(), err) + + _, err = deamonset.CreateDeamonset(w.client, w.cluster.ID, namespace.Name, 1, "", "", false, false) + require.NoError(w.T(), err) +} + func TestWorkloadTestSuite(t *testing.T) { suite.Run(t, new(WorkloadTestSuite)) } diff --git a/tests/validation/tests/v3_api/test_workload.py b/tests/validation/tests/v3_api/test_workload.py index a2addd92181..4ca19d980ea 100644 --- a/tests/validation/tests/v3_api/test_workload.py +++ b/tests/validation/tests/v3_api/test_workload.py @@ -68,7 +68,7 @@ def test_wl_statefulset(): ) validate_workload(p_client, workload, "statefulSet", ns.name) - +#Converted to go test in TestWorkloadDaemonSet def test_wl_daemonset(): p_client = namespace["p_client"] ns = namespace["ns"]