-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
142 lines (116 loc) · 4.75 KB
/
build.gradle.kts
File metadata and controls
142 lines (116 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import aws.sdk.kotlin.gradle.dsl.skipPublishing
import java.io.Closeable
import java.net.URLClassLoader
description = "Common HTTP Client Engine Test Suite"
extra["moduleName"] = "aws.smithy.kotlin.http.test"
skipPublishing()
kotlin {
sourceSets {
commonMain {
dependencies {
implementation(project(":runtime:protocol:http-client"))
implementation(project(":runtime:protocol:http-test"))
implementation(libs.kotlinx.coroutines.test)
implementation(project(":runtime:testing"))
}
}
jvmMain {
dependencies {
implementation(libs.ktor.server.jetty.jakarta)
implementation(libs.ktor.network.tls.certificates)
implementation(libs.okhttp)
implementation(project(":runtime:protocol:http-client-engines:http-client-engine-default"))
implementation(project(":runtime:protocol:http-client-engines:http-client-engine-crt"))
implementation(project(":runtime:protocol:http-client-engines:http-client-engine-okhttp"))
implementation(project(":runtime:protocol:http-client-engines:http-client-engine-okhttp4"))
implementation(libs.slf4j.simple)
}
}
jvmAndNativeMain {
dependencies {
implementation(libs.ktor.server.core)
implementation(libs.kotlinx.coroutines.test)
}
}
jvmTest {
dependencies {
implementation(libs.docker.core)
implementation(libs.docker.transport.zerodep)
implementation(project(":runtime:observability:telemetry-defaults"))
}
}
all {
languageSettings.optIn("aws.smithy.kotlin.runtime.InternalApi")
}
}
}
abstract class TestServerProvider :
BuildService<TestServerProvider.Params>,
AutoCloseable {
interface Params : BuildServiceParameters {
val sslConfigPath: Property<String>
val classpath: ConfigurableFileCollection
}
private var server: Closeable? = null
fun startServers() {
if (server != null) return
try {
println("[TestServers] start")
val urlClassLoaderSource = parameters.classpath.map { it.toURI().toURL() }.toTypedArray()
val loader = URLClassLoader(urlClassLoaderSource, ClassLoader.getSystemClassLoader())
val mainClass = loader.loadClass("aws.smithy.kotlin.runtime.http.test.util.TestServersKt")
val main = mainClass.getMethod("startServers", String::class.java)
server = main.invoke(null, parameters.sslConfigPath.get()) as Closeable
println("[TestServers] started")
} catch (cause: Throwable) {
println("[TestServers] failed: ${cause.message}")
throw cause
}
}
override fun close() {
server?.close()
server = null
println("[TestServers] stopped")
}
}
val testServerProvider = gradle.sharedServices.registerIfAbsent("testServers", TestServerProvider::class) {
parameters.sslConfigPath.set(File.createTempFile("ssl-", ".cfg").absolutePath)
}
afterEvaluate {
testServerProvider.get().parameters.classpath.from(kotlin.targets.getByName("jvm").compilations["test"].runtimeDependencyFiles!!)
}
abstract class StartTestServersTask : DefaultTask() {
@get:Internal
abstract val serverProvider: Property<TestServerProvider>
@TaskAction
fun start() {
serverProvider.get().startServers()
}
}
val osName = System.getProperty("os.name")
val startTestServers = tasks.register<StartTestServersTask>("startTestServers") {
dependsOn(tasks["jvmJar"])
usesService(testServerProvider)
serverProvider.set(testServerProvider)
}
val testTasks = listOf("allTests", "jvmTest")
.forEach {
tasks.named(it) {
dependsOn(startTestServers)
usesService(testServerProvider)
}
}
tasks.jvmTest {
// set test environment for proxy tests
systemProperty("MITM_PROXY_SCRIPTS_ROOT", projectDir.resolve("proxy-scripts").absolutePath)
systemProperty("SSL_CONFIG_PATH", testServerProvider.get().parameters.sslConfigPath.get())
val enableProxyTestsProp = "aws.test.http.enableProxyTests"
val runningInCodeBuild = System.getenv().containsKey("CODEBUILD_BUILD_ID")
val runningInLinux = System.getProperty("os.name").contains("Linux", ignoreCase = true)
val shouldRunProxyTests = !runningInCodeBuild && runningInLinux
systemProperty(enableProxyTestsProp, System.getProperties().getOrDefault(enableProxyTestsProp, shouldRunProxyTests))
}