Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: add augmented class info tests #438

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ReconciledResourceAugmentedClassInfo asResourceTargeting() {
}

@SuppressWarnings("rawtypes")
public static ReconciledAugmentedClassInfo createFor(ClassInfo resourceCI, String reconcilerName,
public static ReconciledAugmentedClassInfo createFor(ClassInfo resourceCI, String name,
IndexView index, Logger log, Map<String, Object> context) {
var isResource = false;
var isCR = false;
Expand All @@ -79,12 +79,12 @@ public static ReconciledAugmentedClassInfo createFor(ClassInfo resourceCI, Strin

ReconciledAugmentedClassInfo reconciledInfo;
if (isCR) {
reconciledInfo = new CustomResourceAugmentedClassInfo(resourceCI, reconcilerName);
reconciledInfo = new CustomResourceAugmentedClassInfo(resourceCI, name);
} else if (isResource) {
reconciledInfo = new ReconciledResourceAugmentedClassInfo<>(resourceCI, HAS_METADATA, 0,
reconcilerName);
name);
} else {
reconciledInfo = new ReconciledAugmentedClassInfo<>(resourceCI, OBJECT, 0, reconcilerName);
reconciledInfo = new ReconciledAugmentedClassInfo<>(resourceCI, OBJECT, 0, name);
}
// make sure the associated resource is properly initialized
reconciledInfo.augmentIfKept(index, log, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.quarkiverse.operatorsdk.common;

import static org.junit.jupiter.api.Assertions.*;

import java.util.AbstractMap.SimpleEntry;
import java.util.List;

import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.junit.jupiter.api.Test;

import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.client.CustomResource;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
import io.quarkus.test.common.TestClassIndexer;

class ResourceAssociatedAugmentedClassInfoTest {

@Test
void getClassNamesToRegisterForReflection() {
final var indexAndInfo = create(ConfigMapReconciler.class);
final var index = indexAndInfo.getKey();
final var info = indexAndInfo.getValue();
info.augmentIfKept(index, null, null);

assertEquals(List.of(ConfigMap.class.getName()), info.getClassNamesToRegisterForReflection());
}

private static SimpleEntry<Index, ClassInfo> getClassInfo(Class<? extends Reconciler<?>> testClass) {
final var index = TestClassIndexer.readIndex(testClass);
return new SimpleEntry<>(index, index.getClassByName(DotName.createSimple(testClass.getName())));
}

private static SimpleEntry<Index, ResourceAssociatedAugmentedClassInfo> create(Class<? extends Reconciler<?>> testClass) {
final var indexAndClassInfo = getClassInfo(testClass);
final var classInfo = indexAndClassInfo.getValue();
return new SimpleEntry<>(indexAndClassInfo.getKey(),
new ResourceAssociatedAugmentedClassInfo(classInfo, Constants.RECONCILER, 1,
ConfigurationUtils.getReconcilerName(
classInfo)));
}

private static class ConfigMapReconciler implements Reconciler<ConfigMap> {

@Override
public UpdateControl<ConfigMap> reconcile(ConfigMap configMap, Context<ConfigMap> context) {
return null;
}
}

private static class TestCRReconciler implements Reconciler<TestCR> {

@Override
public UpdateControl<TestCR> reconcile(TestCR testCR, Context<TestCR> context) {
return null;
}
}

private static class TestCR extends CustomResource<TestCRSpec, TestCRStatus> {
}

private static class TestCRSpec {
}

private static class TestCRStatus {
}
}