@Test public void shouldNotUpdateIfNoImageChangeTrigger() { givenAConnection(); givenTheImageStreamExistsTo("myimagename"); IDeploymentConfig dc = createResource(IDeploymentConfig.class); when(dc.getTriggers()).thenReturn(Collections.EMPTY_LIST); when(connection.getResource( ResourceKind.DEPLOYMENT_CONFIG, project.getName(), parameters.getResourceName())) .thenReturn(dc); assertFalse( job.updateTriggerIfUpdate(connection, project.getName(), parameters.getResourceName())); }
@Test public void shouldUpdateImageTagIfItDifferesFromExisting() { givenAConnection(); givenTheImageStreamExistsTo("myimagename"); givenTheDeploymentConfigExistFor("myimagename", "v0", NAMESPACE, ResourceKind.IMAGE_STREAM_TAG); doReturn(DOCKER_NEW_TAG).when(job).getSourceImage(); IResource resource = connection.getResource( ResourceKind.DEPLOYMENT_CONFIG, project.getName(), parameters.getResourceName()); IDeploymentImageChangeTrigger trigger = (IDeploymentImageChangeTrigger) ((IDeploymentConfig) resource).getTriggers().toArray()[0]; assertThat(job.doRun(monitor)).isEqualTo(Status.OK_STATUS); verify(trigger, times(1)).setFrom(new DockerImageURI(null, null, "myimagename", "v1")); }
private void givenTheDeploymentConfigExistFor( String name, String tag, String triggerNamespace, String triggerKind) { IDeploymentImageChangeTrigger trigger = mock(IDeploymentImageChangeTrigger.class); when(trigger.getType()).thenReturn(DeploymentTriggerType.IMAGE_CHANGE); when(trigger.getNamespace()).thenReturn(triggerNamespace); when(trigger.getKind()).thenReturn(triggerKind); when(trigger.getFrom()).thenReturn(new DockerImageURI(null, null, name, tag)); IDeploymentConfig dc = createResource( IDeploymentConfig.class, new IResourceVisitor<IDeploymentConfig>() { @Override public void visit(IDeploymentConfig resource) { Collection<IDeploymentTrigger> triggers = new ArrayList<IDeploymentTrigger>(); triggers.add(trigger); when(resource.getTriggers()).thenReturn(triggers); } }); when(connection.getResource( ResourceKind.DEPLOYMENT_CONFIG, project.getName(), parameters.getResourceName())) .thenReturn(dc); }
private void givenTheImageStreamExistsTo(String name) { IImageStream is = createResource(IImageStream.class); when(connection.getResource(ResourceKind.IMAGE_STREAM, project.getName(), name)).thenReturn(is); }