Skip to content

Commit

Permalink
Test operator selectors/labels
Browse files Browse the repository at this point in the history
  • Loading branch information
michalxo committed May 2, 2024
1 parent db12c5b commit e92cc28
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ public String getExpectedVersion() {
}
}

public void containExpectedSelectors(Map<String, String> selectors, Map<String, String> expectedSelectors) {
expectedSelectors.entrySet().forEach(e -> {
assertThat("Selectors do not contain expected key", selectors.containsKey(e.getKey()));
assertThat("Selectors do not contain expected value", selectors.containsValue(e.getValue()));
});
}

public void containExpectedLabels(HasMetadata resource, Map<String, String> expectedLabels) {
Map<String, String> labels = resource.getMetadata().getLabels();
expectedLabels.entrySet().forEach(e -> {
assertThat("Selectors do not contain expected key", labels.containsKey(e.getKey()));
assertThat("Selectors do not contain expected value", labels.containsValue(e.getValue()));
});
}

/******************************************************************************************************************
* Default setup and teardown methods
******************************************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import io.fabric8.kubernetes.api.model.Quantity;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServicePort;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.ReplicaSet;
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
import io.fabric8.openshift.api.model.Route;
import org.assertj.core.api.Assertions;
Expand Down Expand Up @@ -949,4 +951,25 @@ void testAcceptorWithPublishNotReadyAddressAsFalseByDefault() {
.isTrue();
ResourceManager.deleteArtemis(testNamespace, broker);
}

@Test
@TestValidSince(ArtemisVersion.VERSION_2_28)
void testOperatorSelector() {
String brokerName = "brk-selector";
ActiveMQArtemis artemisBroker = ResourceManager.createArtemis(testNamespace, brokerName);
Deployment operatorDeployment = getClient().getDeployment(testNamespace, operator.getOperatorName());
ReplicaSet operatorRS = getClient().getReplicaSetsWithPrefix(testNamespace, operator.getOperatorName()).get(0);
Pod operatorPod = getClient().getFirstPodByPrefixName(testNamespace, operator.getOperatorName());

LOGGER.info("[{}] Check selectors in Operator Deployment and ReplicaSet", testNamespace);
// amq-broker-operator --> operator.getOperatorOldName();
Map<String, String> expectedSelectors = Map.of("name", operator.getOperatorOldName());
containExpectedSelectors(operatorDeployment.getSpec().getSelector().getMatchLabels(), expectedSelectors);
containExpectedSelectors(operatorRS.getSpec().getSelector().getMatchLabels(), expectedSelectors);

LOGGER.info("[{}] Check labels in deployed operator Pod {}", testNamespace, operatorPod.getMetadata().getName());
containExpectedLabels(operatorPod, expectedSelectors);

ResourceManager.deleteArtemis(testNamespace, artemisBroker);
}
}

0 comments on commit e92cc28

Please sign in to comment.