Fix GerritMaintenance E2E tests Change-Id: I0cea15210961cfee53c2d047f14b4dc3de5a0769
diff --git a/operator/src/test/java/com/google/gerrit/k8s/operator/maintenance/GerritMaintenanceGitGcE2E.java b/operator/src/test/java/com/google/gerrit/k8s/operator/maintenance/GerritMaintenanceGitGcE2E.java index 53b2687..32cf9e4 100644 --- a/operator/src/test/java/com/google/gerrit/k8s/operator/maintenance/GerritMaintenanceGitGcE2E.java +++ b/operator/src/test/java/com/google/gerrit/k8s/operator/maintenance/GerritMaintenanceGitGcE2E.java
@@ -26,14 +26,12 @@ import com.google.gerrit.k8s.operator.network.IngressType; import com.google.gerrit.k8s.operator.test.AbstractGerritOperatorE2ETest; import io.fabric8.kubernetes.api.model.batch.v1.CronJob; -import io.fabric8.kubernetes.api.model.batch.v1.Job; import java.util.List; import java.util.Set; import org.junit.jupiter.api.Test; public class GerritMaintenanceGitGcE2E extends AbstractGerritOperatorE2ETest { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - static final String GITGC_SCHEDULE = "*/1 * * * *"; @Test void testGitGcAllProjectsCreationAndDeletion() { @@ -49,7 +47,6 @@ () -> { assertGerritMaintenanceCreation(gm.getMetadata().getName()); assertGitGcCronJobCreation(gcCronJobName); - assertGitGcJobCreation(gcCronJobName); }); logger.atInfo().log("Deleting test GitMaintenance object: %s", gm); @@ -62,7 +59,7 @@ GerritMaintenance gm = GerritMaintenanceTestHelper.createGerritMaintenanceWithGitGcs( operator.getNamespace(), List.of(Set.of("All-Projects", "test"))); - + client.resource(gm).createOrReplace(); logger.atInfo().log("Waiting max 2 minutes for GerritMaintenance to be created."); String gcCronJobName = gm.getSpec().getProjects().getGc().get(0).getName(); await() @@ -71,7 +68,6 @@ () -> { assertGerritMaintenanceCreation(gm.getMetadata().getName()); assertGitGcCronJobCreation(gcCronJobName); - assertGitGcJobCreation(gcCronJobName); }); client.resource(gm).delete(); @@ -83,6 +79,7 @@ GerritMaintenance gm = GerritMaintenanceTestHelper.createGerritMaintenanceWithGitGcs( operator.getNamespace(), List.of(Set.of(), selectedProjects)); + client.resource(gm).createOrReplace(); String gmName = gm.getMetadata().getName(); logger.atInfo().log("Waiting max 2 minutes for GerritMaintenance to be created."); @@ -199,13 +196,6 @@ }); } - private void assertGitGcJobCreation(String gitGcName) { - List<Job> jobRuns = - client.batch().v1().jobs().inNamespace(operator.getNamespace()).list().getItems(); - assert (jobRuns.size() > 0); - assert (jobRuns.get(0).getMetadata().getName().startsWith(gitGcName)); - } - @Override protected IngressType getIngressType() { return IngressType.NONE;
diff --git a/operator/src/test/java/com/google/gerrit/k8s/operator/maintenance/GerritMaintenanceTestHelper.java b/operator/src/test/java/com/google/gerrit/k8s/operator/maintenance/GerritMaintenanceTestHelper.java index 34a131f..82ea3bd 100644 --- a/operator/src/test/java/com/google/gerrit/k8s/operator/maintenance/GerritMaintenanceTestHelper.java +++ b/operator/src/test/java/com/google/gerrit/k8s/operator/maintenance/GerritMaintenanceTestHelper.java
@@ -1,5 +1,20 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package com.google.gerrit.k8s.operator.maintenance; +import com.google.common.flogger.FluentLogger; import com.google.gerrit.k8s.operator.api.model.maintenance.GerritMaintenance; import com.google.gerrit.k8s.operator.api.model.maintenance.GerritMaintenanceSpec; import com.google.gerrit.k8s.operator.api.model.maintenance.GerritProjectsTasks; @@ -24,6 +39,8 @@ import org.apache.commons.lang3.RandomStringUtils; public class GerritMaintenanceTestHelper { + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); + public static GerritMaintenance createGerritMaintenanceWithGitGcs( String namespace, List<Set<String>> projectSets) { GerritMaintenanceSpec spec = new GerritMaintenanceSpec(); @@ -31,6 +48,8 @@ List<GitGcTask> gcTasks = new ArrayList<>(); for (Set<String> projects : projectSets) { GitGcTask gitGc = new GitGcTask(); + gitGc.setName(RandomStringUtils.randomAlphabetic(10).toLowerCase()); + gitGc.setSchedule("0 0 * * *"); gitGc.setInclude(projects); gcTasks.add(gitGc); } @@ -40,10 +59,11 @@ GerritMaintenance gm = new GerritMaintenance(); gm.setMetadata( new ObjectMetaBuilder() - .withName(RandomStringUtils.randomAlphabetic(10)) + .withName(RandomStringUtils.randomAlphabetic(10).toLowerCase()) .withNamespace(namespace) .build()); gm.setSpec(spec); + logger.atInfo().log("Created GerritMaintenance: %s", gm); return gm; } }