Skip to content

Commit

Permalink
test: disable all host data related tests when running against TC cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
npepinpe committed Apr 27, 2022
1 parent 8affb17 commit 589b05d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.camunda.zeebe.model.bpmn.Bpmn;
import io.camunda.zeebe.model.bpmn.BpmnModelInstance;
import io.zeebe.containers.util.TestUtils;
import io.zeebe.containers.util.TestcontainersSupport.DisabledIfTestcontainersCloud;
import io.zeebe.containers.util.TopologyAssert;
import java.io.IOException;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -99,6 +100,7 @@ void shouldExposeAllPortsButGateway(final String testName, final ZeebeBrokerNode
@ParameterizedTest(name = "{0}")
@MethodSource("reuseDataTestCases")
@EnabledOnOs(LINUX)
@DisabledIfTestcontainersCloud
void shouldReuseHostDataOnRestart(
final String testName,
final BrokerNodeProvider brokerNodeProvider,
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/io/zeebe/containers/ZeebeHostDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@
package io.zeebe.containers;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.condition.OS.LINUX;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.command.InspectContainerResponse.Mount;
import com.github.dockerjava.api.model.Volume;
import io.zeebe.containers.util.TestUtils;
import io.zeebe.containers.util.TestcontainersSupport.DisabledIfTestcontainersCloud;
import java.nio.file.Path;
import java.util.Objects;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.io.TempDir;
import org.testcontainers.DockerClientFactory;

@EnabledOnOs(LINUX)
@DisabledIfTestcontainersCloud
final class ZeebeHostDataTest {
@Test
void shouldAttachToZeebeContainer(final @TempDir Path dataDir) {
Expand Down
55 changes: 55 additions & 0 deletions src/test/java/io/zeebe/containers/util/TestcontainersSupport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright © 2022 camunda services GmbH ([email protected])
*
* 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 io.zeebe.containers.util;

import com.github.dockerjava.api.model.Info;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.junit.jupiter.api.condition.DisabledIf;
import org.testcontainers.DockerClientFactory;

@API(status = Status.INTERNAL)
public final class TestcontainersSupport {
private TestcontainersSupport() {}

/**
* Returns whether tests run against Testcontainers Cloud or not by checking the server version.
*
* <p>This isn't perfect as it's clearly breaking implementation details, but it works for now.
*/
public static boolean isCloudEnv() {
if (System.getenv().containsKey("TC_CLOUD_TOKEN")) {
return true;
}

final Info dockerInfo = DockerClientFactory.lazyClient().infoCmd().exec();
return dockerInfo.getServerVersion() != null
&& dockerInfo.getServerVersion().endsWith("testcontainerscloud");
}

@DisabledIf(
value = "io.zeebe.containers.util.TestcontainersSupport#isCloudEnv",
disabledReason = "Testcontainers Cloud does not support mounting host files")
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface DisabledIfTestcontainersCloud {}
}

0 comments on commit 589b05d

Please sign in to comment.