Search in sources :

Example 1 with TestKubernetesExtension

use of org.eclipse.jkube.gradle.plugin.TestKubernetesExtension in project jkube by eclipse.

the class KubernetesBuildTaskTest 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(isBuildServiceApplicable);
        if (isBuildError) {
            doThrow(new JKubeServiceException("Exception during Build")).when(mock).build(any());
        }
    });
    isBuildServiceApplicable = true;
    isBuildError = false;
    extension = new TestKubernetesExtension();
    when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension);
    extension.images = Collections.singletonList(ImageConfiguration.builder().name("foo/bar:latest").build(BuildConfiguration.builder().dockerFile("Dockerfile").build()).build());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) DockerBuildService(org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService) DefaultProperty(org.gradle.api.internal.provider.DefaultProperty) Assert.assertThrows(org.junit.Assert.assertThrows) Mockito.doThrow(org.mockito.Mockito.doThrow) After(org.junit.After) AssertionsForInterfaceTypes.assertThat(org.assertj.core.api.AssertionsForInterfaceTypes.assertThat) Mockito.mockConstruction(org.mockito.Mockito.mockConstruction) Assertions(org.assertj.core.api.Assertions) TestKubernetesExtension(org.eclipse.jkube.gradle.plugin.TestKubernetesExtension) Before(org.junit.Before) MockedConstruction(org.mockito.MockedConstruction) DockerAccessFactory(org.eclipse.jkube.kit.build.service.docker.DockerAccessFactory) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) GradleException(org.gradle.api.GradleException) KubernetesExtension(org.eclipse.jkube.gradle.plugin.KubernetesExtension) Property(org.gradle.api.provider.Property) DockerAccess(org.eclipse.jkube.kit.build.service.docker.access.DockerAccess) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) DockerAccess(org.eclipse.jkube.kit.build.service.docker.access.DockerAccess) DockerBuildService(org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) DockerAccessFactory(org.eclipse.jkube.kit.build.service.docker.DockerAccessFactory) TestKubernetesExtension(org.eclipse.jkube.gradle.plugin.TestKubernetesExtension) Before(org.junit.Before)

Example 2 with TestKubernetesExtension

use of org.eclipse.jkube.gradle.plugin.TestKubernetesExtension in project jkube by eclipse.

the class KubernetesDebugTaskTest method setUp.

@Before
public void setUp() throws IOException {
    debugServiceMockedConstruction = mockConstruction(DebugService.class);
    extension = new TestKubernetesExtension();
    when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension);
}
Also used : DebugService(org.eclipse.jkube.kit.config.service.DebugService) TestKubernetesExtension(org.eclipse.jkube.gradle.plugin.TestKubernetesExtension) Before(org.junit.Before)

Example 3 with TestKubernetesExtension

use of org.eclipse.jkube.gradle.plugin.TestKubernetesExtension in project jkube by eclipse.

the class KubernetesLogTaskTest method setUp.

@Before
public void setUp() throws IOException {
    extension = new TestKubernetesExtension();
    extension.isUseColor = false;
    when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension);
}
Also used : TestKubernetesExtension(org.eclipse.jkube.gradle.plugin.TestKubernetesExtension) Before(org.junit.Before)

Example 4 with TestKubernetesExtension

use of org.eclipse.jkube.gradle.plugin.TestKubernetesExtension in project jkube by eclipse.

the class KubernetesPushTaskTest method runTask_withSkipPush_shouldDoNothing.

@Test
public void runTask_withSkipPush_shouldDoNothing() throws JKubeServiceException {
    // Given
    extension = new TestKubernetesExtension() {

        @Override
        public Property<Boolean> getSkipPush() {
            return new DefaultProperty<>(Boolean.class).value(true);
        }
    };
    when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension);
    final KubernetesPushTask pushTask = new KubernetesPushTask(KubernetesExtension.class);
    when(pushTask.getName()).thenReturn("k8sPush");
    // When
    pushTask.runTask();
    // Then
    Assertions.assertThat(dockerBuildServiceMockedConstruction.constructed()).isEmpty();
    verify(pushTask.jKubeServiceHub.getBuildService(), times(0)).push(any(), anyInt(), any(), anyBoolean());
    verify(taskEnvironment.logger, times(1)).lifecycle(contains("k8s: `k8sPush` task is skipped."));
}
Also used : DefaultProperty(org.gradle.api.internal.provider.DefaultProperty) Property(org.gradle.api.provider.Property) DefaultProperty(org.gradle.api.internal.provider.DefaultProperty) TestKubernetesExtension(org.eclipse.jkube.gradle.plugin.TestKubernetesExtension) Test(org.junit.Test)

Example 5 with TestKubernetesExtension

use of org.eclipse.jkube.gradle.plugin.TestKubernetesExtension in project jkube by eclipse.

the class KubernetesUndeployTaskTest method setUp.

@Before
public void setUp() throws IOException {
    clusterAccessMockedConstruction = mockConstruction(ClusterAccess.class, (mock, ctx) -> {
        final KubernetesClient kubernetesClient = mock(KubernetesClient.class);
        when(mock.createDefaultClient()).thenReturn(kubernetesClient);
        when(kubernetesClient.getMasterUrl()).thenReturn(new URL("http://kubernetes-cluster"));
    });
    kubernetesUndeployServiceMockedConstruction = mockConstruction(KubernetesUndeployService.class);
    extension = new TestKubernetesExtension();
    when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension);
}
Also used : ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess) KubernetesUndeployService(org.eclipse.jkube.kit.config.service.kubernetes.KubernetesUndeployService) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assert.assertThrows(org.junit.Assert.assertThrows) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) Paths(java.nio.file.Paths) KubernetesExtension(org.eclipse.jkube.gradle.plugin.KubernetesExtension) After(org.junit.After) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Mockito.mockConstruction(org.mockito.Mockito.mockConstruction) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) TestKubernetesExtension(org.eclipse.jkube.gradle.plugin.TestKubernetesExtension) Before(org.junit.Before) MockedConstruction(org.mockito.MockedConstruction) Mockito.mock(org.mockito.Mockito.mock) KubernetesUndeployService(org.eclipse.jkube.kit.config.service.kubernetes.KubernetesUndeployService) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess) URL(java.net.URL) TestKubernetesExtension(org.eclipse.jkube.gradle.plugin.TestKubernetesExtension) Before(org.junit.Before)

Aggregations

TestKubernetesExtension (org.eclipse.jkube.gradle.plugin.TestKubernetesExtension)15 Before (org.junit.Before)11 Test (org.junit.Test)9 KubernetesExtension (org.eclipse.jkube.gradle.plugin.KubernetesExtension)6 DefaultProperty (org.gradle.api.internal.provider.DefaultProperty)6 Property (org.gradle.api.provider.Property)6 IOException (java.io.IOException)5 After (org.junit.After)5 Rule (org.junit.Rule)5 MockedConstruction (org.mockito.MockedConstruction)5 Mockito.mock (org.mockito.Mockito.mock)5 Mockito.mockConstruction (org.mockito.Mockito.mockConstruction)5 Mockito.times (org.mockito.Mockito.times)5 Mockito.when (org.mockito.Mockito.when)5 Assert.assertThrows (org.junit.Assert.assertThrows)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 Mockito.verify (org.mockito.Mockito.verify)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)3 URL (java.net.URL)3 Collections (java.util.Collections)3