Skip to content

Commit

Permalink
test(provider/cf): Add test on cf deploy converter (#4644)
Browse files Browse the repository at this point in the history
The recent change to the artifact handling in cloudfoundry deploy
may have caused a regression. It's still not clear to me exactly
what the change is, but adding this (currently passing) unit test
as a start so that hopefully we can make it fail and track the
bug.
  • Loading branch information
ezimanyi committed Jun 2, 2020
1 parent b1e586e commit 1a2534f
Showing 1 changed file with 35 additions and 0 deletions.
Expand Up @@ -22,6 +22,8 @@
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.netflix.spinnaker.clouddriver.artifacts.ArtifactCredentialsRepository;
import com.netflix.spinnaker.clouddriver.cloudfoundry.artifacts.ArtifactCredentialsFromString;
import com.netflix.spinnaker.clouddriver.cloudfoundry.cache.CacheRepository;
Expand Down Expand Up @@ -71,6 +73,9 @@ private static CloudFoundryCredentials createCredentials(String name) {
.organization(
CloudFoundryOrganization.builder().id("org-guid").name("org").build())
.build()));

when(cloudFoundryClient.getApplications().findServerGroupId(any(), any()))
.thenReturn("servergroup-id");
}

return new CloudFoundryCredentials(
Expand Down Expand Up @@ -205,4 +210,34 @@ void convertManifestMapToApplicationAttributesUsingWithNoBuildpacks() {
.setDiskQuota("1024")
.setBuildpacks(Collections.emptyList()));
}

@Test
void convertDescriptionTest() {
Map<String, Object> description =
ImmutableMap.of(
"applicationArtifact",
ImmutableMap.of(
"artifactAccount",
"destinationAccount",
"type",
"cloudfoundry/app",
"name",
"server-group-name",
"location",
"cf-region"),
"credentials", "test",
"manifest",
ImmutableList.of(
ImmutableMap.of("applications", ImmutableList.of(ImmutableMap.of()))));

DeployCloudFoundryServerGroupDescription result = converter.convertDescription(description);

assertThat(result.getArtifactCredentials()).isNotNull();
assertThat(result.getArtifactCredentials().getName()).isEqualTo("cloudfoundry");
assertThat(result.getApplicationArtifact()).isNotNull();
assertThat(result.getApplicationArtifact().getName()).isEqualTo("server-group-name");
assertThat(result.getApplicationArtifact().getArtifactAccount())
.isEqualTo("destinationAccount");
assertThat(result.getApplicationArtifact().getUuid()).isEqualTo("servergroup-id");
}
}

0 comments on commit 1a2534f

Please sign in to comment.