-
Notifications
You must be signed in to change notification settings - Fork 70
chore(test): Adds swabbie integration tests for docker builds #669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jasonmcintosh
wants to merge
9
commits into
spinnaker:master
Choose a base branch
from
armory-io:addIntegrationTests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
49f004f
chore(test): Adds swabbie integration tests for docker builds
jasonmcintosh fa7c82b
fix(test): Fix integration test port
jasonmcintosh eae69a1
chore(gha): Update GHA to use image and additional JVM flags
jasonmcintosh 480650c
Merge branch 'master' into addIntegrationTests
jasonmcintosh b95a7ed
fix(gha): Add tests to PR as well
jasonmcintosh 49ce8dc
fix(config): Use kork-config to set the standard properties for spinn…
jasonmcintosh 18040e4
Merge branch 'master' into addIntegrationTests
jasonmcintosh 535e302
Merge branch 'master' into addIntegrationTests
jasonmcintosh 7df6313
Merge branch 'master' into addIntegrationTests
jasonmcintosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
swabbie-integration/src/test/java/com/netflix/spinnaker/swabbie/StandaloneContainerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| * Copyright 2024 Salesforce, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.netflix.spinnaker.swabbie; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import java.net.URI; | ||
| import java.net.http.HttpClient; | ||
| import java.net.http.HttpRequest; | ||
| import java.net.http.HttpResponse; | ||
| import java.util.Map; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestInfo; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.testcontainers.containers.GenericContainer; | ||
| import org.testcontainers.containers.Network; | ||
| import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
| import org.testcontainers.containers.wait.strategy.Wait; | ||
| import org.testcontainers.junit.jupiter.Testcontainers; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
| @Testcontainers | ||
| class StandaloneContainerTest { | ||
|
|
||
| private static final String REDIS_NETWORK_ALIAS = "redisHost"; | ||
|
|
||
| private static final int REDIS_PORT = 6379; | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(StandaloneContainerTest.class); | ||
|
|
||
| private static final Network network = Network.newNetwork(); | ||
|
|
||
| // Using Valkey due to licensing | ||
| private static GenericContainer redis = | ||
| new GenericContainer(DockerImageName.parse("valkey/valkey:7-bookworm")) | ||
| .withNetwork(network) | ||
| .withNetworkAliases(REDIS_NETWORK_ALIAS) | ||
| .withExposedPorts(REDIS_PORT); | ||
|
|
||
| private static GenericContainer swabbieContainer; | ||
|
|
||
| @BeforeAll | ||
| static void setupOnce() throws Exception { | ||
| String fullDockerImageName = System.getenv("FULL_DOCKER_IMAGE_NAME"); | ||
|
|
||
| // Skip the tests if there's no docker image. This allows gradlew build to work. | ||
| assumeTrue(fullDockerImageName != null); | ||
|
|
||
| redis.start(); | ||
|
|
||
| DockerImageName dockerImageName = DockerImageName.parse(fullDockerImageName); | ||
|
|
||
| swabbieContainer = | ||
| new GenericContainer(dockerImageName) | ||
| .withNetwork(network) | ||
| .withExposedPorts(8092) | ||
| .dependsOn(redis) | ||
| .waitingFor(Wait.forHealthcheck()) | ||
| .withEnv("SPRING_APPLICATION_JSON", getSpringApplicationJson()); | ||
|
|
||
| Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(logger); | ||
| swabbieContainer.start(); | ||
| swabbieContainer.followOutput(logConsumer); | ||
| } | ||
|
|
||
| private static String getSpringApplicationJson() throws JsonProcessingException { | ||
| String redisUrl = "redis://" + REDIS_NETWORK_ALIAS + ":" + REDIS_PORT; | ||
| logger.info("redisUrl: '{}'", redisUrl); | ||
| Map<String, String> properties = Map.of("redis.connection", redisUrl); | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| return mapper.writeValueAsString(properties); | ||
| } | ||
|
|
||
| @AfterAll | ||
| static void cleanupOnce() { | ||
| if (swabbieContainer != null) { | ||
| swabbieContainer.stop(); | ||
| } | ||
|
|
||
| if (redis != null) { | ||
| redis.stop(); | ||
| } | ||
| } | ||
|
|
||
| @BeforeEach | ||
| void init(TestInfo testInfo) { | ||
| System.out.println("--------------- Test " + testInfo.getDisplayName()); | ||
| } | ||
|
|
||
| @Test | ||
| void testHealthCheck() throws Exception { | ||
| // hit an arbitrary endpoint | ||
| HttpRequest request = | ||
| HttpRequest.newBuilder() | ||
| .uri( | ||
| new URI( | ||
| "http://" | ||
| + swabbieContainer.getHost() | ||
| + ":" | ||
| + swabbieContainer.getFirstMappedPort() | ||
| + "/health")) | ||
| .GET() | ||
| .build(); | ||
|
|
||
| HttpClient client = HttpClient.newHttpClient(); | ||
|
|
||
| HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); | ||
| assertThat(response).isNotNull(); | ||
| logger.info("response: {}, {}", response.statusCode(), response.body()); | ||
| assertThat(response.statusCode()).isEqualTo(200); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <!-- | ||
|
|
||
| Copyright 2024 Salesforce, Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| --> | ||
| <configuration> | ||
|
|
||
| <!-- see https://java.testcontainers.org/supported_docker_environment/logging_config/ --> | ||
| <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
| <encoder> | ||
| <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
| </encoder> | ||
| </appender> | ||
|
|
||
| <root level="DEBUG"> | ||
| <appender-ref ref="STDOUT" /> | ||
| </root> | ||
|
|
||
| <logger name="org.testcontainers" level="INFO"/> | ||
| <logger name="tc" level="INFO"/> | ||
| <logger name="com.github.dockerjava" level="WARN"/> | ||
| <logger name="com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.wire" level="OFF"/> | ||
|
|
||
| </configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| dependencies { | ||
| testImplementation "com.fasterxml.jackson.core:jackson-databind" | ||
| testImplementation "org.assertj:assertj-core" | ||
| testImplementation "org.junit.jupiter:junit-jupiter-api" | ||
| testImplementation "org.slf4j:slf4j-api" | ||
| testImplementation "org.testcontainers:testcontainers" | ||
| testImplementation "org.testcontainers:junit-jupiter" | ||
| testRuntimeOnly "ch.qos.logback:logback-classic" | ||
| } | ||
|
|
||
| test.configure { | ||
| def fullDockerImageName = System.getenv('FULL_DOCKER_IMAGE_NAME') | ||
| onlyIf("there is a docker image to test") { | ||
| fullDockerImageName != null && fullDockerImageName.trim() != '' | ||
| } | ||
| } | ||
|
|
||
| test { | ||
| // So stdout and stderr from the just-built container are available in CI | ||
| testLogging.showStandardStreams = true | ||
|
|
||
| // Run the tests when the docker image changes | ||
| inputs.property 'fullDockerImageName', System.getenv('FULL_DOCKER_IMAGE_NAME') | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pr.yml also needs this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks will add that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And....it fails:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah :) That's that kork config with the default locations if I recall right. Will dig & fix here later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/spinnaker/kork/blob/2b857f57c85a8c821e35da68c1207fbf00cb335d/kork-config/src/main/java/com/netflix/spinnaker/kork/boot/DefaultPropertiesBuilder.java#L32C1-L33C1 this was what was thinking. Checking on the config here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI fixed this with latest PR, but working through all the "clouddriver isn't available" as part of the integration tests. Got some more work to do on the downstream deps.