Skip to content

Commit 7b4aa97

Browse files
authored
Add kokoro test configs (#1149)
* Add kokoro test configs * Remove android and assembly modules from pom for tests * Fix comment format * Debug test * Fix Java version header test on Java 9 * Remove debug statement
1 parent 9144d21 commit 7b4aa97

File tree

10 files changed

+138
-2
lines changed

10 files changed

+138
-2
lines changed

.kokoro/build.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Copyright 2018 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eo pipefail
17+
18+
cd github/google-api-java-client/
19+
20+
# Print out Java
21+
java -version
22+
echo $JOB_TYPE
23+
24+
# Skip android and assembly tests? Imported from Travis config
25+
sed -i 's/<module>google-api-client-android<\/module>//' pom.xml
26+
sed -i 's/<module>google-api-client-assembly<\/module>//' pom.xml
27+
28+
mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
29+
mvn test -B

.kokoro/common.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Download trampoline resources. These will be in ${KOKORO_GFILE_DIR}
4+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
5+
6+
# All builds use the trampoline script to run in docker.
7+
build_file: "google-api-java-client/.kokoro/trampoline.sh"
8+
9+
# Tell the trampoline which build file to use.
10+
env_vars: {
11+
key: "TRAMPOLINE_BUILD_FILE"
12+
value: "github/google-api-java-client/.kokoro/build.sh"
13+
}

.kokoro/presubmit/common.cfg

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Build logs will be here
4+
action {
5+
define_artifacts {
6+
regex: "**/*sponge_log.xml"
7+
}
8+
}
9+
10+
# Download trampoline resources.
11+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
12+
13+
# Use the trampoline script to run in docker.
14+
build_file: "google-api-java-client/.kokoro/trampoline.sh"
15+
16+
env_vars: {
17+
key: "TRAMPOLINE_BUILD_FILE"
18+
value: "github/google-api-java-client/.kokoro/build.sh"
19+
}
20+
21+
env_vars: {
22+
key: "JOB_TYPE"
23+
value: "test"
24+
}

.kokoro/presubmit/java10.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java10"
7+
}

.kokoro/presubmit/java7.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java7"
7+
}

.kokoro/presubmit/java8.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
7+
}

.kokoro/presubmit/java9.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java9"
7+
}

.kokoro/trampoline.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# Copyright 2018 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
set -eo pipefail
16+
# Always run the cleanup script, regardless of the success of bouncing into
17+
# the container.
18+
function cleanup() {
19+
chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
20+
${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
21+
echo "cleanup";
22+
}
23+
trap cleanup EXIT
24+
python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"

google-api-client/src/main/java/com/google/api/client/googleapis/services/AbstractGoogleClientRequest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected AbstractGoogleClientRequest(AbstractGoogleClient abstractGoogleClient,
136136
*
137137
*/
138138
private static class ApiClientVersion {
139-
private static final String JAVA_VERSION = formatSemver(System.getProperty("java.version"));
139+
private static final String JAVA_VERSION = getJavaVersion();
140140
private static final String OS_NAME = formatName(System.getProperty("os.name"));
141141
private static final String OS_VERSION = formatSemver(System.getProperty("os.version"));
142142

@@ -152,6 +152,16 @@ private static String build(AbstractGoogleClient client) {
152152
);
153153
}
154154

155+
private static String getJavaVersion() {
156+
String version = System.getProperty("java.version");
157+
// Java 9 doesn't report a semver here: instead it's something like 9-Debian+0-x-y
158+
if (version.startsWith("9")) {
159+
return "9.0.0";
160+
} else {
161+
return formatSemver(version);
162+
}
163+
}
164+
155165
private static String formatName(String name) {
156166
// Only lowercase letters, digits, and "-" are allowed
157167
return name.toLowerCase().replaceAll("[^\\w\\d\\-]", "-");

google-api-client/src/test/java/com/google/api/client/googleapis/services/AbstractGoogleClientRequestTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,15 @@ public LowLevelHttpRequest buildRequest(String method, String url) throws IOExce
222222
return new MockLowLevelHttpRequest() {
223223
@Override
224224
public LowLevelHttpResponse execute() throws IOException {
225-
assertTrue(getFirstHeaderValue(expectedHeader).matches(expectedHeaderValue));
225+
String firstHeader = getFirstHeaderValue(expectedHeader);
226+
assertTrue(
227+
String.format(
228+
"Expected header value to match %s, instead got %s.",
229+
expectedHeaderValue,
230+
firstHeader
231+
),
232+
firstHeader.matches(expectedHeaderValue)
233+
);
226234
return new MockLowLevelHttpResponse();
227235
}
228236
};

0 commit comments

Comments
 (0)