Skip to content

Commit

Permalink
fix(errors): throw a useful error for invalid manifest configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgogerly committed May 2, 2023
1 parent f60cf3b commit 9ddde04
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Expand Up @@ -50,6 +50,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import retrofit.client.Response;
Expand Down Expand Up @@ -167,6 +168,12 @@ private Supplier<Iterable<Object>> fetchAndParseManifestYaml(Artifact manifestAr
}

private Artifact getManifestArtifact(StageExecution stage, ManifestContext context) {
if (StringUtils.hasText(context.getManifestArtifactId())
&& StringUtils.hasText(context.getManifestArtifactAccount())) {
throw new IllegalArgumentException(
"Artifact account must not be set if referencing an artifact produced by a previous stage.");
}

Artifact manifestArtifact =
Optional.ofNullable(
artifactUtils.getBoundArtifactForStage(
Expand Down
Expand Up @@ -276,6 +276,23 @@ void optionalArtifacts() {
assertThat(result.getOptionalArtifacts()).isEqualTo(optionalArtifacts);
}

@Test
void shouldThrowExceptionWhenArtifactIdAndAccountBothSet() {
StageExecutionImpl stage = new StageExecutionImpl();

DeployManifestContext context =
DeployManifestContext.builder()
.manifestArtifactId("my-manifest-artifact-id")
.manifestArtifactAccount("some-other-account")
.skipExpressionEvaluation(false)
.source(Source.Artifact)
.build();

assertThatThrownBy(() -> manifestEvaluator.evaluate(stage, context))
.isInstanceOf(IllegalArgumentException.class);
verifyNoInteractions(oortService);
}

@Test
void shouldThrowExceptionWhenFailedEvaluatingManifestExpressions() {
StageExecutionImpl stage = new StageExecutionImpl();
Expand Down

0 comments on commit 9ddde04

Please sign in to comment.