From f41ba43cfdd6db94f768e581f3954b0583eedf99 Mon Sep 17 00:00:00 2001 From: Deepak Punia Date: Fri, 29 Nov 2024 18:35:05 +0530 Subject: [PATCH] Fix project creation --- go.mod | 2 +- tests/e2e/installations_test.go | 2 +- tests/e2e/suite_test.go | 35 ++++++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index ba0e952..23b56dd 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.22.7 require ( github.com/pkg/errors v0.9.1 // indirect - github.com/rancher/norman v0.0.0-20240708202514-a0127673d1b9 // indirect + github.com/rancher/norman v0.0.0-20240708202514-a0127673d1b9 github.com/rancher/shepherd v0.0.0-20240913161053-43e119d13724 // rancher/shepherd release/v2.9-HEAD commit github.com/sirupsen/logrus v1.9.3 // indirect k8s.io/apimachinery v0.30.2 diff --git a/tests/e2e/installations_test.go b/tests/e2e/installations_test.go index 42f83b7..ffb8b40 100644 --- a/tests/e2e/installations_test.go +++ b/tests/e2e/installations_test.go @@ -25,7 +25,7 @@ import ( e2e "k8s.io/kubernetes/test/e2e/framework" ) -const exampleAppProjectName = "demo-project" +const exampleAppProjectName = "System" var _ = Describe("Observability Installation Test Suite", func() { var clientWithSession *rancher.Client diff --git a/tests/e2e/suite_test.go b/tests/e2e/suite_test.go index c962445..6d37cfb 100644 --- a/tests/e2e/suite_test.go +++ b/tests/e2e/suite_test.go @@ -20,6 +20,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/rancher/norman/types" rancher "github.com/rancher/shepherd/clients/rancher" management "github.com/rancher/shepherd/clients/rancher/generated/management/v3" clusters "github.com/rancher/shepherd/extensions/clusters" @@ -59,6 +60,8 @@ func TestE2E(t *testing.T) { // This setup will run once for the entire test suite var _ = BeforeSuite(func() { + project = nil + testSession := session.NewSession() sess = testSession @@ -77,14 +80,32 @@ var _ = BeforeSuite(func() { registrySetting, err = client.Management.Setting.ByID("system-default-registry") Expect(err).NotTo(HaveOccurred()) - // Create project - projectConfig := &management.Project{ - ClusterID: cluster.ID, - Name: exampleAppProjectName, - } - project, err = client.Management.Project.Create(projectConfig) + projectsList, err := client.Management.Project.List(&types.ListOpts{ + Filters: map[string]interface{}{ + "clusterId": cluster.ID, + }, + }) Expect(err).NotTo(HaveOccurred()) - Expect(project.Name).To(Equal(exampleAppProjectName)) + + for i := range projectsList.Data { + p := &projectsList.Data[i] + if p.Name == exampleAppProjectName { + project = p + break + } + } + + // Check if project was found + if project == nil { + projectConfig := &management.Project{ + ClusterID: cluster.ID, + Name: exampleAppProjectName, + } + + project, err = client.Management.Project.Create(projectConfig) + Expect(err).NotTo(HaveOccurred()) + Expect(project.Name).To(Equal(exampleAppProjectName)) + } }) // This teardown will run once after all the tests in the suite are done