Skip to content

Commit

Permalink
fix: add token refreshing and refine the fbc test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Jing Qi <[email protected]>

The fbc test cases need to take several minutes for build pipelineRun and release
pipelineRun. Since the access token expired sooner than before, the test cases
are refined and added the token refreshing during the test.
  • Loading branch information
jinqi7 committed Mar 20, 2024
1 parent 33f036d commit cecfd94
Showing 1 changed file with 33 additions and 111 deletions.
144 changes: 33 additions & 111 deletions tests/release/pipelines/fbc_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appservice "github.com/redhat-appstudio/application-api/api/v1alpha1"
"github.com/redhat-appstudio/e2e-tests/pkg/clients/github"
"github.com/redhat-appstudio/e2e-tests/pkg/clients/has"
"github.com/redhat-appstudio/e2e-tests/pkg/constants"
"github.com/redhat-appstudio/e2e-tests/pkg/framework"
Expand All @@ -38,7 +37,6 @@ const (
var snapshot *appservice.Snapshot
var releaseCR *releaseapi.Release
var releasePr, buildPr *tektonv1.PipelineRun
var gh *github.Github
var err error
var devWorkspace = utils.GetEnv(constants.RELEASE_DEV_WORKSPACE_ENV, constants.DevReleaseTeam)
var managedWorkspace = utils.GetEnv(constants.RELEASE_MANAGED_WORKSPACE_ENV, constants.ManagedReleaseTeam)
Expand Down Expand Up @@ -72,29 +70,14 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
var fbcPreGAECPolicyName = "fbc-prega-policy-" + util.GenerateRandomString(4)

AfterEach(framework.ReportFailure(&devFw))
stageOptions := utils.Options{
ToolchainApiUrl: os.Getenv(constants.TOOLCHAIN_API_URL_ENV),
KeycloakUrl: os.Getenv(constants.KEYLOAK_URL_ENV),
OfflineToken: os.Getenv(constants.OFFLINE_TOKEN_ENV),
}


Describe("with FBC happy path", Label("fbcHappyPath"), func() {
var component *appservice.Component
BeforeAll(func() {
devFw, err = framework.NewFrameworkWithTimeout(
devWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)

managedFw, err = framework.NewFrameworkWithTimeout(
managedWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
managedNamespace = managedFw.UserNamespace

// Linking the build secret to the pipeline service account in dev namespace.
Expand All @@ -103,7 +86,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-

_, err = devFw.AsKubeDeveloper.HasController.CreateApplication(fbcApplicationName, devNamespace)
Expect(err).NotTo(HaveOccurred())
GinkgoWriter.Println("Application %s is created", fbcApplicationName)
GinkgoWriter.Println("Create application :", fbcApplicationName)

_, err = devFw.AsKubeDeveloper.ReleaseController.CreateReleasePlan(fbcReleasePlanName, devNamespace, fbcApplicationName, managedNamespace, "true")
Expect(err).NotTo(HaveOccurred())
Expand All @@ -115,19 +98,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
})

AfterAll(func() {
devFw, err = framework.NewFrameworkWithTimeout(
devWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())

managedFw, err = framework.NewFrameworkWithTimeout(
managedWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)
Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(fbcApplicationName, devNamespace, false)).NotTo(HaveOccurred())
Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(fbcEnterpriseContractPolicyName, managedNamespace, false)).NotTo(HaveOccurred())
Expect(managedFw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(fbcReleasePlanAdmissionName, managedNamespace, false)).NotTo(HaveOccurred())
Expand All @@ -152,23 +124,12 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
var component *appservice.Component

BeforeAll(func() {
devFw, err = framework.NewFrameworkWithTimeout(
devWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())

managedFw, err = framework.NewFrameworkWithTimeout(
managedWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)

_, err = devFw.AsKubeDeveloper.HasController.CreateApplication(fbcHotfixAppName, devNamespace)
Expect(err).NotTo(HaveOccurred())
GinkgoWriter.Println("Application %s is created", fbcHotfixAppName)
GinkgoWriter.Println("Create application :", fbcHotfixAppName)

_, err = devFw.AsKubeDeveloper.ReleaseController.CreateReleasePlan(fbcHotfixRPName, devNamespace, fbcHotfixAppName, managedNamespace, "true")
Expect(err).NotTo(HaveOccurred())
Expand All @@ -179,19 +140,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
})

AfterAll(func() {
devFw, err = framework.NewFrameworkWithTimeout(
devWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())

managedFw, err = framework.NewFrameworkWithTimeout(
managedWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)
Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(fbcHotfixAppName, devNamespace, false)).NotTo(HaveOccurred())
Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(fbcHotfixECPolicyName, managedNamespace, false)).NotTo(HaveOccurred())
Expect(managedFw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(fbcHotfixRPAName, managedNamespace, false)).NotTo(HaveOccurred())
Expand All @@ -216,23 +166,12 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
var component *appservice.Component

BeforeAll(func() {
devFw, err = framework.NewFrameworkWithTimeout(
devWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())

managedFw, err = framework.NewFrameworkWithTimeout(
managedWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)

_, err = devFw.AsKubeDeveloper.HasController.CreateApplication(fbcPreGAAppName, devNamespace)
Expect(err).NotTo(HaveOccurred())
GinkgoWriter.Println("Application %s is created", fbcPreGAAppName)
GinkgoWriter.Println("Create application :", fbcPreGAAppName)

_, err = devFw.AsKubeDeveloper.ReleaseController.CreateReleasePlan(fbcPreGARPName, devNamespace, fbcPreGAAppName, managedNamespace, "true")
Expect(err).NotTo(HaveOccurred())
Expand All @@ -243,19 +182,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
})

AfterAll(func() {
devFw, err = framework.NewFrameworkWithTimeout(
devWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())

managedFw, err = framework.NewFrameworkWithTimeout(
managedWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)
if !CurrentSpecReport().Failed() {
Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(fbcPreGAAppName, devNamespace, false)).NotTo(HaveOccurred())
Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(fbcPreGAECPolicyName, managedNamespace, false)).NotTo(HaveOccurred())
Expand Down Expand Up @@ -300,17 +228,7 @@ func assertReleasePipelineRunSucceeded(devFw, managedFw framework.Framework, dev
return nil
}, 5 * time.Minute, releasecommon.DefaultInterval).Should(Succeed(), "timed out when waiting for Snapshot and Release being created")

stageOptions := utils.Options{
ToolchainApiUrl: os.Getenv(constants.TOOLCHAIN_API_URL_ENV),
KeycloakUrl: os.Getenv(constants.KEYLOAK_URL_ENV),
OfflineToken: os.Getenv(constants.OFFLINE_TOKEN_ENV),
}
mFw, err := framework.NewFrameworkWithTimeout(
managedWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
mFw := newFramework(managedWorkspace)
Eventually(func() error {
releasePr, err = mFw.AsKubeAdmin.ReleaseController.GetPipelineRunInNamespace(mFw.UserNamespace, releaseCR.GetName(), releaseCR.GetNamespace())
if err != nil {
Expand All @@ -329,19 +247,7 @@ func assertReleasePipelineRunSucceeded(devFw, managedFw framework.Framework, dev
}

func assertReleaseCRSucceeded(devFw framework.Framework, devNamespace, managedNamespace, fbcAppName string, component *appservice.Component) {
GinkgoWriter.Println("snapshot: ", snapshot.Name)

stageOptions := utils.Options{
ToolchainApiUrl: os.Getenv(constants.TOOLCHAIN_API_URL_ENV),
KeycloakUrl: os.Getenv(constants.KEYLOAK_URL_ENV),
OfflineToken: os.Getenv(constants.OFFLINE_TOKEN_ENV),
}
dFw, err := framework.NewFrameworkWithTimeout(
devWorkspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
dFw := newFramework(devWorkspace)
Eventually(func() error {
releaseCR, err = dFw.AsKubeDeveloper.ReleaseController.GetRelease("", snapshot.Name, devNamespace)
if err != nil {
Expand Down Expand Up @@ -420,3 +326,19 @@ func createFBCReleasePlanAdmission(fbcRPAName string, managedFw framework.Framew
})
Expect(err).NotTo(HaveOccurred())
}

func newFramework(workspace string) *framework.Framework {

stageOptions := utils.Options{
ToolchainApiUrl: os.Getenv(constants.TOOLCHAIN_API_URL_ENV),
KeycloakUrl: os.Getenv(constants.KEYLOAK_URL_ENV),
OfflineToken: os.Getenv(constants.OFFLINE_TOKEN_ENV),
}
fw, err := framework.NewFrameworkWithTimeout(
workspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
return fw
}

0 comments on commit cecfd94

Please sign in to comment.