Skip to content

Commit

Permalink
feat(test): Clouddriver integration tests (#4827)
Browse files Browse the repository at this point in the history
* feat(test): First commit of integration tests module

* feat(test): Added k3s for integration tests

* feat(test): Make spotless happy

* feat(test): First deploy manifests int tests

* feat(test): Run integration tests on PR builds

* feat(test): Moved integration tests to cloud provider module

* feat(test): Explicit code over test helpers

* feat(test): Cleanup compilation warnings

* feat(test): More deploy manifest tests
  • Loading branch information
german-muzquiz committed Sep 10, 2020
1 parent 3d467ed commit 0c85aac
Show file tree
Hide file tree
Showing 15 changed files with 1,541 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Expand Up @@ -26,3 +26,5 @@ jobs:
${{ runner.os }}-gradle-
- name: Build
run: ./gradlew -PenableCrossCompilerPlugin=true build
- name: Integration Tests
run: ./gradlew --info integrationTest
41 changes: 40 additions & 1 deletion clouddriver-kubernetes/clouddriver-kubernetes.gradle
Expand Up @@ -3,7 +3,21 @@ plugins {
}

tasks.compileGroovy.enabled = false
sourceSets.main.java.srcDirs = ['src/main/java']

sourceSets {
main {
java.srcDirs = ['src/main/java']
}
integration {
java.srcDirs = ["src/integration/java"]
resources.srcDirs = ["src/integration/resources"]
}
}

configurations {
integrationImplementation.extendsFrom testImplementation
integrationRuntime.extendsFrom testRuntime
}

tasks.withType(JavaCompile) {
options.compilerArgs += [
Expand Down Expand Up @@ -77,4 +91,29 @@ dependencies {
testImplementation "org.spockframework:spock-core"
testImplementation "org.spockframework:spock-spring"
testImplementation "org.springframework:spring-test"


integrationImplementation project(":clouddriver-web")
integrationImplementation "org.springframework.boot:spring-boot-starter-test"
integrationImplementation "org.testcontainers:testcontainers"
integrationImplementation "org.testcontainers:mysql"
integrationImplementation "org.testcontainers:junit-jupiter"
integrationImplementation "mysql:mysql-connector-java"
integrationImplementation ("io.rest-assured:rest-assured:4.0.0") {
// Exclude groovy pulled in by rest-assured, so we use kork's version
exclude group: "org.codehaus.groovy", module: "groovy"
}
integrationImplementation "org.yaml:snakeyaml"
}

task integrationTest(type: Test) {
description = 'Runs kubernetes provider integration tests.'
group = 'verification'

environment "PROJECT_ROOT", project.rootDir.toString()
useJUnitPlatform()

testClassesDirs = sourceSets.integration.output.classesDirs
classpath = sourceSets.integration.runtimeClasspath
shouldRunAfter test
}
@@ -0,0 +1,66 @@
/*
* Copyright 2020 Armory
*
* 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.clouddriver.kubernetes.it;

import static io.restassured.RestAssured.get;
import static org.hamcrest.Matchers.hasItems;

import com.netflix.spinnaker.clouddriver.Main;
import com.netflix.spinnaker.clouddriver.kubernetes.it.containers.KubernetesCluster;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.TestPropertySource;

@SpringBootTest(
classes = {Main.class},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = {"spring.config.location = classpath:clouddriver.yml"})
public abstract class BaseTest {

public static final String APP1_NAME = "testApp1";
public static final String ACCOUNT1_NAME = "account1";

@LocalServerPort int port;

public static final KubernetesCluster kubeCluster;

static {
kubeCluster = KubernetesCluster.getInstance(ACCOUNT1_NAME);
kubeCluster.start();
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}

public String baseUrl() {
return "http://localhost:" + port;
}

@BeforeEach
void givenAccountsReady() {
Response response = get(baseUrl() + "/credentials");
response
.then()
.log()
.ifValidationFails()
.assertThat()
.statusCode(200)
.and()
.body("name", hasItems(ACCOUNT1_NAME));
}
}

0 comments on commit 0c85aac

Please sign in to comment.