use of org.eclipse.jkube.kit.common.util.KubernetesHelper in project jkube by eclipse.
the class OpenShiftResourceTaskTest method runTask_resolvesGroupInImageNameToNamespaceSetViaConfiguration_whenNoNamespaceDetected.
@Test
public void runTask_resolvesGroupInImageNameToNamespaceSetViaConfiguration_whenNoNamespaceDetected() {
try (MockedStatic<KubernetesHelper> kubernetesHelper = Mockito.mockStatic(KubernetesHelper.class)) {
// Given
kubernetesHelper.when(KubernetesHelper::getDefaultNamespace).thenReturn("test-custom-namespace");
kubernetesHelper.when(() -> KubernetesHelper.getKind(any())).thenReturn("DeploymentConfig");
kubernetesHelper.when(() -> KubernetesHelper.getName((HasMetadata) any())).thenReturn("test-project");
ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("%g/%a").build(BuildConfiguration.builder().from("test-base-image:latest").build()).build();
extension.images = Collections.singletonList(imageConfiguration);
OpenShiftResourceTask resourceTask = new OpenShiftResourceTask(OpenShiftExtension.class);
// When
resourceTask.runTask();
// Then
assertThat(resourceTask.resolvedImages).hasSize(1).singleElement().hasFieldOrPropertyWithValue("name", "test-custom-namespace/test-project");
}
}
use of org.eclipse.jkube.kit.common.util.KubernetesHelper in project jkube by eclipse.
the class OpenShiftWatchTaskTest method setUp.
@Before
public void setUp() throws IOException {
clusterAccessMockedConstruction = mockConstruction(ClusterAccess.class, (mock, ctx) -> {
final OpenShiftClient openShiftClient = mock(OpenShiftClient.class);
when(openShiftClient.getMasterUrl()).thenReturn(new URL("http://openshiftapps.com:6443"));
when(mock.createDefaultClient()).thenReturn(openShiftClient);
});
watcherManagerMockedStatic = mockStatic(WatcherManager.class);
kubernetesHelperMockedStatic = mockStatic(KubernetesHelper.class);
extension = new TestOpenShiftExtension();
when(taskEnvironment.project.getExtensions().getByType(OpenShiftExtension.class)).thenReturn(extension);
kubernetesHelperMockedStatic.when(KubernetesHelper::getDefaultNamespace).thenReturn(null);
extension.isFailOnNoKubernetesJson = false;
}
use of org.eclipse.jkube.kit.common.util.KubernetesHelper in project jkube by eclipse.
the class KubernetesWatchTaskTest method setUp.
@Before
public void setUp() throws IOException {
// Mock required for environments with no DOCKER available (don't remove)
dockerAccessFactoryMockedConstruction = mockConstruction(DockerAccessFactory.class, (mock, ctx) -> when(mock.createDockerAccess(any())).thenReturn(mock(DockerAccess.class)));
dockerBuildServiceMockedConstruction = mockConstruction(DockerBuildService.class, (mock, ctx) -> {
when(mock.isApplicable()).thenReturn(true);
});
clusterAccessMockedConstruction = mockConstruction(ClusterAccess.class, (mock, ctx) -> {
final KubernetesClient kubernetesClient = mock(KubernetesClient.class);
when(kubernetesClient.getMasterUrl()).thenReturn(new URL("http://kubernetes-cluster"));
when(mock.createDefaultClient()).thenReturn(kubernetesClient);
});
watcherManagerMockedStatic = mockStatic(WatcherManager.class);
kubernetesHelperMockedStatic = mockStatic(KubernetesHelper.class);
extension = new TestKubernetesExtension();
when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension);
kubernetesHelperMockedStatic.when(KubernetesHelper::getDefaultNamespace).thenReturn(null);
extension.isFailOnNoKubernetesJson = false;
}
use of org.eclipse.jkube.kit.common.util.KubernetesHelper in project jkube by eclipse.
the class KubernetesLogTaskTest method runTask_withIOException_shouldThrowException.
@Test
public void runTask_withIOException_shouldThrowException() {
try (MockedStatic<KubernetesHelper> mockStatic = Mockito.mockStatic(KubernetesHelper.class)) {
// Given
mockStatic.when(() -> KubernetesHelper.loadResources(any())).thenThrow(new IOException("IO error with logs"));
KubernetesLogTask kubernetesLogTask = new KubernetesLogTask(KubernetesExtension.class);
// When
final Exception result = assertThrows(GradleException.class, kubernetesLogTask::runTask);
// Then
assertThat(result).hasMessage("Failure in getting logs");
}
}
Aggregations