Add Cloud Gateway smoke tests
See gh-149
This commit is contained in:
committed by
Andy Wilkinson
parent
5025acf98f
commit
0ed5498b45
@@ -32,6 +32,7 @@ groups:
|
||||
- cloud-discovery-consul
|
||||
- cloud-discovery-eureka
|
||||
- cloud-discovery-zookeeper
|
||||
- cloud-gateway
|
||||
- cloud-function-web
|
||||
- cloud-function-webflux
|
||||
- cloud-loadbalancing-web
|
||||
|
||||
30
cloud/cloud-gateway/build.gradle
Normal file
30
cloud/cloud-gateway/build.gradle
Normal file
@@ -0,0 +1,30 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot'
|
||||
id 'org.springframework.aot.smoke-test'
|
||||
id 'org.graalvm.buildtools.native'
|
||||
}
|
||||
|
||||
ext {
|
||||
set('springCloudVersion', "2022.0.0-SNAPSHOT")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform(
|
||||
org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
|
||||
implementation(
|
||||
platform("org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"))
|
||||
implementation("org.springframework.boot:spring-boot-starter")
|
||||
implementation("org.springframework.cloud:spring-cloud-starter-gateway")
|
||||
implementation("org.springframework.cloud:spring-cloud-starter-loadbalancer")
|
||||
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
|
||||
appTestImplementation(project(":aot-smoke-test-support"))
|
||||
|
||||
}
|
||||
|
||||
aotSmokeTest {
|
||||
webApplication = true
|
||||
}
|
||||
|
||||
10
cloud/cloud-gateway/docker-compose.yml
Normal file
10
cloud/cloud-gateway/docker-compose.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
version: '3'
|
||||
services:
|
||||
test-service:
|
||||
image: springcloud/test-service:latest
|
||||
ports:
|
||||
- "8081"
|
||||
demo-service:
|
||||
image: springcloud/demo-service:latest
|
||||
ports:
|
||||
- "8082"
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.example.cloud.gateway;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.smoketest.support.junit.ApplicationTest;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ApplicationTest
|
||||
public class CloudGatewayApplicationAotTests {
|
||||
|
||||
@Test
|
||||
void shouldRouteRequests(WebTestClient client) {
|
||||
client.get().uri("test-service").exchange().expectStatus().isOk().expectBody()
|
||||
.consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("test"));
|
||||
client.get().uri("demo-service").exchange().expectStatus().isOk().expectBody()
|
||||
.consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("demo"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.example.cloud.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class CloudGatewayApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CloudGatewayApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.example.cloud.gateway;
|
||||
|
||||
import org.springframework.cloud.gateway.route.RouteLocator;
|
||||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
@Configuration
|
||||
class RoutesConfig {
|
||||
|
||||
@Bean
|
||||
RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
|
||||
return builder
|
||||
.routes().route("demo_service_route", route -> route.path("/demo-service/**").and()
|
||||
.method(HttpMethod.GET).filters(filter -> filter.stripPrefix(1)).uri("lb://demo-service"))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
31
cloud/cloud-gateway/src/main/resources/application.yml
Normal file
31
cloud/cloud-gateway/src/main/resources/application.yml
Normal file
@@ -0,0 +1,31 @@
|
||||
logging:
|
||||
level:
|
||||
org.springframework.cloud: DEBUG
|
||||
spring:
|
||||
application:
|
||||
name: gateway
|
||||
cloud:
|
||||
discovery:
|
||||
client:
|
||||
simple:
|
||||
instances:
|
||||
test-service:
|
||||
- uri: http://${TEST-SERVICE_HOST:localhost}:${TEST-SERVICE_PORT_8081:8081}
|
||||
demo-service:
|
||||
- uri: http://${DEMO-SERVICE_HOST:localhost}:${DEMO-SERVICE_PORT_8082:8082}
|
||||
loadbalancer:
|
||||
eager-load:
|
||||
clients:
|
||||
- demo-service
|
||||
- test-service
|
||||
gateway:
|
||||
routes:
|
||||
- id: test_service_route
|
||||
uri: lb://test-service
|
||||
predicates:
|
||||
- Path=/test-service/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- name: Retry
|
||||
args:
|
||||
retries: 3
|
||||
Reference in New Issue
Block a user