@Test public void validate_shouldValidatePluggableArtifactStoreId() { final ValidationContext validationContext = mock(ValidationContext.class); final PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("Artifact-ID", "Store-ID"); final ArtifactStores artifactStores = mock(ArtifactStores.class); assertFalse(artifactConfig.hasErrors()); when(validationContext.artifactStores()).thenReturn(artifactStores); when(validationContext.isWithinPipelines()).thenReturn(true); when(validationContext.getPipeline()).thenReturn(PipelineConfigMother.pipelineConfig("pipe")); when(artifactStores.find("Store-ID")).thenReturn(null); artifactConfig.validate(validationContext); assertTrue(artifactConfig.hasErrors()); assertThat(artifactConfig.errors().getAll(), hasSize(1)); assertThat(artifactConfig.errors().getAllOn("storeId"), hasSize(1)); assertThat(artifactConfig.errors().on("storeId"), is("Artifact store with id `Store-ID` does not exist. Please correct the `storeId` attribute on pipeline `pipe`.")); }
@Test public void validate_shouldValidateUniquenessOnId() { final PluggableArtifactConfig existingConfig = new PluggableArtifactConfig("Artifact-ID", "Store-ID"); final List<ArtifactConfig> artifactConfigConfigs = Arrays.asList(existingConfig); final PluggableArtifactConfig newConfig = new PluggableArtifactConfig("Artifact-ID", "Store-ID"); newConfig.validateUniqueness(artifactConfigConfigs); assertTrue(newConfig.hasErrors()); assertTrue(existingConfig.hasErrors()); assertThat(newConfig.errors().on("id"), is("Duplicate pluggable artifacts with id `Artifact-ID` defined.")); assertThat(existingConfig.errors().on("id"), is("Duplicate pluggable artifacts with id `Artifact-ID` defined.")); }
@Test public void validate_shouldValidateArtifactPropertiesConfig() { final PluggableArtifactConfig existingConfig = new PluggableArtifactConfig("id1", "Store-ID", create("Foo", false, "Bar")); final List<ArtifactConfig> artifactConfigConfigs = Arrays.asList(existingConfig); final PluggableArtifactConfig newConfig = new PluggableArtifactConfig("id2", "Store-ID", create("Foo", false, "Bar")); newConfig.validateUniqueness(artifactConfigConfigs); assertTrue(newConfig.hasErrors()); assertTrue(existingConfig.hasErrors()); assertThat(newConfig.errors().on("id"), is("Duplicate pluggable artifacts configuration defined.")); assertThat(existingConfig.errors().on("id"), is("Duplicate pluggable artifacts configuration defined.")); }
@Test public void validate_shouldAddAnErrorIfArtifactIdIsInvalid() { PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("asf@%", "f"); final ArtifactStores artifactStores = new ArtifactStores(new ArtifactStore("docker", "cd.go.docker")); final boolean result = artifactConfig.validateTree(ValidationContextMother.validationContext(artifactStores)); assertFalse(result); assertThat(artifactConfig.errors().getAllOn("id"), is(Arrays.asList("Invalid pluggable artifact id name 'asf@%'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."))); }
@Test public void validateTree_shouldValidatePresenceOfId() { final PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("", "s3"); final ArtifactStores artifactStores = new ArtifactStores(new ArtifactStore("s3", "cd.go.s3")); final boolean result = artifactConfig.validateTree(ValidationContextMother.validationContext(artifactStores)); assertFalse(result); assertThat(artifactConfig.errors().getAllOn("id"), is(Arrays.asList("\"Id\" is required for PluggableArtifact", "Invalid pluggable artifact id name ''. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."))); }
@Test public void validateTree_presenceOfStoreIdInArtifactStores() { PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("installer", ""); final ArtifactStores artifactStores = new ArtifactStores(new ArtifactStore("docker", "cd.go.docker")); final boolean result = artifactConfig.validateTree(ValidationContextMother.validationContext(artifactStores)); assertFalse(result); assertThat(artifactConfig.errors().getAllOn("storeId"), is(Arrays.asList("\"Store id\" is required for PluggableArtifact"))); }
@Test public void validate_shouldNotErrorWhenArtifactPropertiesConfigurationIsSameForDifferentStores() { final PluggableArtifactConfig existingConfig = new PluggableArtifactConfig("id1", "storeId1", create("Foo", false, "Bar")); final List<ArtifactConfig> artifactConfigConfigs = Arrays.asList(existingConfig); final PluggableArtifactConfig newConfig = new PluggableArtifactConfig("id2", "storeId2", create("Foo", false, "Bar")); newConfig.validateUniqueness(artifactConfigConfigs); assertFalse(newConfig.hasErrors()); assertFalse(existingConfig.hasErrors()); assertNull(newConfig.errors().on("id")); assertNull(existingConfig.errors().on("id")); }