Skip to content

Commit

Permalink
OCPBUGS-10562: fix operator uninstall test
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamilto committed Oct 4, 2023
1 parent d08018d commit 925abcc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Expand Up @@ -88,7 +88,7 @@ describe(`Testing uninstall of ${testOperator.name} Operator`, () => {
modal.shouldBeClosed();
});

xit(`attempts to uninstall the Operator, shows 'Error uninstalling Operator' alert`, () => {
it(`attempts to uninstall the Operator, shows 'Error uninstalling Operator' alert`, () => {
// invalidate the request so operator doesn't get uninstalled
cy.intercept(
'DELETE',
Expand Down
Expand Up @@ -76,6 +76,7 @@ export const UninstallOperatorModal: React.FC<UninstallOperatorModalProps> = ({
const [operandDeletionVerificationError, setOperandDeletionVerificationError] = React.useState(
false,
);
const [subscriptionExistsError, setSubscriptionExistsError] = React.useState('');
const [clusterServiceVersionExistsError, setClusterServiceVersionExistsError] = React.useState(
'',
);
Expand Down Expand Up @@ -135,6 +136,21 @@ export const UninstallOperatorModal: React.FC<UninstallOperatorModalProps> = ({
? getPatchForRemovingPlugins(consoleOperatorConfig, enabledPlugins)
: null;

const subscriptionExists = async () => {
try {
await k8sGetResource({
model: SubscriptionModel,
name: subscription?.metadata?.name,
});
return true;
} catch (err) {
if (err.response.status !== 404) {
setSubscriptionExistsError(err.message);
}
return false;
}
};

const clusterServiceVersionExists = async () => {
try {
await k8sGetResource({
Expand All @@ -144,15 +160,17 @@ export const UninstallOperatorModal: React.FC<UninstallOperatorModalProps> = ({
});
return true;
} catch (err) {
if (err.json.code !== 404) {
if (err.response.status !== 404) {
setClusterServiceVersionExistsError(err.message);
}
return false;
}
};

const operatorUninstallPromises = [
k8sKill(SubscriptionModel, subscription, {}, deleteOptions),
...((await subscriptionExists())
? [k8sKill(SubscriptionModel, subscription, {}, deleteOptions)]
: []),
...(subscription?.status?.installedCSV && (await clusterServiceVersionExists())
? [
k8sKill(
Expand Down Expand Up @@ -363,6 +381,7 @@ export const UninstallOperatorModal: React.FC<UninstallOperatorModalProps> = ({
<>
<UninstallAlert
errorMessage={
subscriptionExistsError ||
clusterServiceVersionExistsError ||
operatorUninstallErrorMessage ||
(operandDeletionErrors.length
Expand Down

0 comments on commit 925abcc

Please sign in to comment.