Skip to content

Commit

Permalink
Added test for Fleet resource count on cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Satyajit Bulage <[email protected]>
  • Loading branch information
sbulage committed Feb 4, 2025
1 parent 14ec805 commit 5e1e4ae
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/cypress/e2e/unit_tests/p1_fleet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1249,3 +1249,31 @@ if (!/\/2\.7/.test(Cypress.env('rancher_version')) && !/\/2\.8/.test(Cypress.env
)
})
};

if (!/\/2\.7/.test(Cypress.env('rancher_version')) && !/\/2\.8/.test(Cypress.env('rancher_version'))) {
describe('Test Fleet Resource Count', { tags: '@p1'}, () => {
qase(155,
it("Fleet-155: Test clusters resource count is correct", { tags: '@fleet-155' }, () => {
const repoName = 'default-cluster-count-155'
const branch = "master"
const path = "simple"
const repoUrl = "https://github.com/rancher/fleet-examples"

cy.addFleetGitRepo({ repoName, repoUrl, branch, path });
cy.clickButton('Create');
cy.checkGitRepoStatus(repoName, '1 / 1', '6 / 6');

// Get the Resource count from GitRepo and store it.
cy.gitRepoResourceCountAsInteger(repoName, 'fleet-default');

// Compare Resource count from GitRepo(stored)
// with resource count from each downstream cluster.
dsAllClusterList.forEach((dsCluster) => {
cy.compareClusterResourceCount(dsCluster);
})

cy.deleteAllFleetRepos();
})
)
});
}
40 changes: 40 additions & 0 deletions tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,43 @@ Cypress.Commands.add('checkGitRepoAfterUpgrade', (repoName, fleetNamespace='flee
cy.filterInSearchBox(repoName);
cy.verifyTableRow(0, /Active|Modified/, repoName);
});

Cypress.Commands.add('gitRepoResourceCountAsInteger', (repoName, fleetNamespace='fleet-local') => {
cy.accesMenuSelection('Continuous Delivery', 'Git Repos');
cy.fleetNamespaceToggle(fleetNamespace);
cy.verifyTableRow(0, 'Active', repoName);
cy.contains(repoName).click()
cy.get('.primaryheader > h1').contains(repoName).should('be.visible')

// Get the Resource count text from UI and convert it into integer.
cy.get("div[data-testid='gitrepo-deployment-summary'] div[class='count']")
.invoke('text')
.then((countText) => {
// Add '7' default resource count available on each cluster.
const gitRepoResourceCount = parseInt(countText.trim(), 10) + 7;
cy.log("GitRepo Resource count is: " + gitRepoResourceCount);
cy.wrap(gitRepoResourceCount).as('gitRepoResourceCount');
})
})

Cypress.Commands.add('compareClusterResourceCount', (clusterName) => {
// Check the resource count from each cluster matches with resources created by GitRepo.
cy.accesMenuSelection('Continuous Delivery', 'Clusters');
cy.contains('.title', 'Clusters').should('be.visible');
cy.filterInSearchBox(clusterName);
cy.verifyTableRow(0, 'Active', clusterName);
cy.get('td.col-link-detail > span').contains(clusterName).click();

// Get the stored 'gitRepoResourceCount' value and
// compare with existing resource count from cluster.
cy.get('@gitRepoResourceCount').then((gitRepoResourceCount) => {
cy.get("div[primary-color-var='--sizzle-success'] div[class='data compact'] > h1")
.invoke('text')
.then((clusterResourceCountText) => {
// Covert it into integer and then compare with resources created via GitRepo.
const resourceCountOnCluster = parseInt(clusterResourceCountText.trim(), 10);
cy.log("Resource count on each cluster is: " + resourceCountOnCluster);
expect(gitRepoResourceCount).to.equal(resourceCountOnCluster);
})
})
})
2 changes: 2 additions & 0 deletions tests/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ declare global {
verifyJobDeleted(repoName: string, verifyJobDeletedEvent?: boolean ): Chainable<Element>;
typeIntoCanvasTermnal(textToType: string): Chainable<Element>;
checkGitRepoAfterUpgrade(repoName: string, fleetNamespace?: string): Chainable<Element>;
gitRepoResourceCountAsInteger(repoName: string, fleetNamespace?: string): Chainable<Element>;
compareClusterResourceCount(clusterName: string): Chainable<Element>;
}
}
}
Expand Down

0 comments on commit 5e1e4ae

Please sign in to comment.