Skip to content

Commit b2d612b

Browse files
committed
split examples and integration test script. update tests
1 parent 878177b commit b2d612b

6 files changed

Lines changed: 167 additions & 64 deletions

File tree

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# This workflow will build the project with Gradle
1+
# This workflow will build the project with Gradle and run examples
22
# Because secrets are not available on external forks, this job is expected to fail
33
# on external pull requests.
44

5-
name: Build project with Gradle & perform releaes checks
5+
name: Build project with Gradle & run examples
66

77
on:
88
push:
@@ -27,10 +27,11 @@ jobs:
2727
uses: actions/setup-python@v2
2828
with:
2929
python-version: '2.7'
30-
- run: python2.7 -m ensurepip && python -m pip install ply && pip install six
30+
# python2.7 -m ensurepip &&
31+
- run: python -m pip install ply && pip install six
3132
- name: Grant execute permissions
3233
run: chmod +x gradlew && chmod +x update-submodules
33-
&& chmod +x generate-ci-auth-file && chmod +x scripts/release-check
34+
&& chmod +x generate-ci-auth-file && chmod +x scripts/run-examples
3435
- name: Set up submodules
3536
run: ./update-submodules
3637
- name: Install new gradle build
@@ -41,5 +42,5 @@ jobs:
4142
APP_SECRET: ${{ secrets.APP_SECRET }}
4243
REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }}
4344
run: ./generate-ci-auth-file
44-
- name: Run release checks
45-
run: ./scripts/release-check $(find `pwd` -name auth_output)
45+
- name: Run examples
46+
run: ./scripts/run-examples $(find `pwd` -name auth_output)

‎proguard/src/main/java/com/dropbox/core/test/proguard/Main.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ private static void testEnumeratedSubtypeSerialization(DbxClientV2 client) throw
9090
assertEquals(file.getSize(), data.length);
9191

9292
Metadata metadata = client.files().getMetadata(path);
93-
94-
// Ignore parentSharedFolderId field; CDM users will fail that check due to nature of CDM member folder.
95-
assertEquals(metadata.getName(), file.getName());
96-
assertEquals(metadata.getPathLower(), file.getPathLower());
97-
assertEquals(metadata.getPathDisplay(), file.getPathDisplay());
93+
assertEquals(metadata, file);
9894
}
9995

10096
for (String path : files.keySet()) {

‎scripts/release-check‎

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,6 @@ run() {
1919
echo "================================================================================"
2020
}
2121

22-
gradle() {
23-
(cd "${DIR}" && run ./gradlew -c standalone-settings.gradle "$@")
24-
}
25-
26-
examples_gradle() {
27-
(cd "${DIR}/examples" && run ./gradlew "$@")
28-
}
29-
30-
android_gradle() {
31-
(cd "${DIR}/examples/android" && run ./gradlew "$@")
32-
}
33-
34-
run_example() {
35-
(cd "${DIR}/examples" && run ./run --fail-on-error "$@")
36-
}
37-
3822
if [ $# -ne 1 ] ; then
3923
script=`basename "${0}"`
4024
echo >&2 "usage: $script production-user-auth.json"
@@ -60,28 +44,9 @@ echo "A series of tests will be performed to verify package is ready for release
6044
echo "These tests may take a while to complete."
6145
echo ""
6246

63-
gradle clean
64-
gradle check
65-
66-
# prepare examples to be run
67-
gradle install
68-
examples_gradle clean
69-
examples_gradle classes
70-
7147
# run examples
72-
DATE=$(date -u '+%Y%m%d%H%M%S')
73-
run_example account-info "${AUTH_FILE}"
74-
cat /dev/urandom | head -c 1024 > "${tempfile}"
75-
run_example upload-file "${AUTH_FILE}" "${tempfile}" /test/dropbox-sdk-java/${DATE}/examples/upload-file/small-1KiB.dat
76-
cat /dev/urandom | head -c $(( 32 << 20 )) > "${tempfile}"
77-
run_example upload-file "${AUTH_FILE}" "${tempfile}" /test/dropbox-sdk-java/${DATE}/examples/upload-file/large-32MiB.dat
78-
79-
# build android
80-
android_gradle clean
81-
android_gradle assemble
48+
./scripts/run-examples ${AUTH_FILE}
8249

83-
# Run integration tests against major HTTP requestor implementations
84-
for requestor in "StandardHttpRequestor" "OkHttpRequestor" "OkHttp3Requestor" ; do
85-
gradle -Pcom.dropbox.test.httpRequestor="${requestor}" -Pcom.dropbox.test.authInfoFile="${AUTH_FILE}" integrationTest proguardTest
86-
done
50+
# run integration tests
51+
./scripts/run-integration-tests ${AUTH_FILE}
8752

‎scripts/run-examples‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
die() {
4+
echo >&2 "error: examples failed"
5+
exit 1
6+
}
7+
8+
# Exit immediately on any error.
9+
set -euf
10+
trap die SIGTERM
11+
12+
DIR=`dirname $(dirname "${BASH_SOURCE[0]}")`
13+
14+
run() {
15+
echo "================================================================================"
16+
echo " CMD: $@"
17+
echo " OUTPUT:"
18+
$@ || die
19+
echo "================================================================================"
20+
}
21+
22+
gradle() {
23+
(cd "${DIR}" && run ./gradlew -c standalone-settings.gradle "$@")
24+
}
25+
26+
examples_gradle() {
27+
(cd "${DIR}/examples" && run ./gradlew "$@")
28+
}
29+
30+
android_gradle() {
31+
(cd "${DIR}/examples/android" && run ./gradlew "$@")
32+
}
33+
34+
run_example() {
35+
(cd "${DIR}/examples" && run ./run --fail-on-error "$@")
36+
}
37+
38+
if [ $# -ne 1 ] ; then
39+
script=`basename "${0}"`
40+
echo >&2 "usage: $script production-user-auth.json"
41+
exit 1
42+
fi
43+
44+
AUTH_FILE="${1}"
45+
46+
if [ ! -f "${AUTH_FILE}" ] ; then
47+
echo >&2 "error: no such file: ${AUTH_FILE}"
48+
exit 1
49+
fi
50+
51+
tempfile=$(mktemp -t `basename "${BASH_SOURCE[0]}"`.XXXXXXXXXX)
52+
function cleanup() {
53+
[ ! -e "${tempfile}" ] || rm -f "${tempfile}"
54+
}
55+
trap cleanup EXIT
56+
57+
echo "Running examples..."
58+
59+
gradle clean
60+
gradle check
61+
62+
# prepare examples to be run
63+
gradle install
64+
examples_gradle clean
65+
examples_gradle classes
66+
67+
# run examples
68+
DATE=$(date -u '+%Y%m%d%H%M%S')
69+
run_example account-info "${AUTH_FILE}"
70+
cat /dev/urandom | head -c 1024 > "${tempfile}"
71+
run_example upload-file "${AUTH_FILE}" "${tempfile}" /test/dropbox-sdk-java/${DATE}/examples/upload-file/small-1KiB.dat
72+
cat /dev/urandom | head -c $(( 32 << 20 )) > "${tempfile}"
73+
run_example upload-file "${AUTH_FILE}" "${tempfile}" /test/dropbox-sdk-java/${DATE}/examples/upload-file/large-32MiB.dat

‎scripts/run-integration-tests‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
die() {
4+
echo >&2 "error: release checks failed"
5+
exit 1
6+
}
7+
8+
# Exit immediately on any error.
9+
set -euf
10+
trap die SIGTERM
11+
12+
DIR=`dirname $(dirname "${BASH_SOURCE[0]}")`
13+
14+
run() {
15+
echo "================================================================================"
16+
echo " CMD: $@"
17+
echo " OUTPUT:"
18+
$@ || die
19+
echo "================================================================================"
20+
}
21+
22+
gradle() {
23+
(cd "${DIR}" && run ./gradlew -c standalone-settings.gradle "$@")
24+
}
25+
26+
android_gradle() {
27+
(cd "${DIR}/examples/android" && run ./gradlew "$@")
28+
}
29+
30+
if [ $# -ne 1 ] ; then
31+
script=`basename "${0}"`
32+
echo >&2 "usage: $script production-user-auth.json"
33+
exit 1
34+
fi
35+
36+
AUTH_FILE="${1}"
37+
38+
if [ ! -f "${AUTH_FILE}" ] ; then
39+
echo >&2 "error: no such file: ${AUTH_FILE}"
40+
exit 1
41+
fi
42+
43+
tempfile=$(mktemp -t `basename "${BASH_SOURCE[0]}"`.XXXXXXXXXX)
44+
function cleanup() {
45+
[ ! -e "${tempfile}" ] || rm -f "${tempfile}"
46+
}
47+
trap cleanup EXIT
48+
49+
echo "Running integration tests..."
50+
51+
gradle clean
52+
gradle check
53+
54+
# prepare examples to be run
55+
gradle install
56+
android_gradle clean
57+
android_gradle assemble
58+
59+
# Run integration tests against major HTTP requestor implementations
60+
for requestor in "StandardHttpRequestor" "OkHttpRequestor" "OkHttp3Requestor" ; do
61+
gradle -Pcom.dropbox.test.httpRequestor="${requestor}" -Pcom.dropbox.test.authInfoFile="${AUTH_FILE}" integrationTest proguardTest
62+
done
63+

‎src/test/java/com/dropbox/core/v2/DbxClientV2IT.java‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.Locale;
1010

1111
import com.dropbox.core.util.IOUtil.ProgressListener;
12+
13+
import org.junit.After;
1214
import org.testng.annotations.Test;
1315

1416
import com.dropbox.core.BadRequestException;
@@ -101,25 +103,28 @@ private void testUploadAndDownload(DbxClientV2 client, boolean trackProgress) th
101103
Metadata actual = client.files().getMetadata(path);
102104
assertWithMessage(actual.getClass().getCanonicalName()).that(actual instanceof FileMetadata).isTrue();
103105

104-
// Ignore parentSharedFolderId field; CDM users will fail that check due to nature of CDM member folder.
105-
assertThat(actual.getName()).isEqualTo(metadata.getName());
106-
assertThat(actual.getPathLower()).isEqualTo(metadata.getPathLower());
107-
assertThat(actual.getPathDisplay()).isEqualTo(metadata.getPathDisplay());
106+
try {
107+
assertThat(actual).isEqualTo(metadata);
108108

109-
if (trackProgress) {
110-
progressListener = createTestListener(contents.length);
111-
}
109+
if (trackProgress) {
110+
progressListener = createTestListener(contents.length);
111+
}
112112

113-
DbxDownloader<FileMetadata> downloader = client.files().download(path);
114-
ByteArrayOutputStream out = new ByteArrayOutputStream();
115-
downloader.download(out, progressListener);
113+
DbxDownloader<FileMetadata> downloader = client.files().download(path);
114+
ByteArrayOutputStream out = new ByteArrayOutputStream();
115+
downloader.download(out, progressListener);
116116

117-
byte [] actualContents = out.toByteArray();
118-
FileMetadata actualResult = downloader.getResult();
117+
byte[] actualContents = out.toByteArray();
118+
FileMetadata actualResult = downloader.getResult();
119119

120-
assertThat(actualResult).isEqualTo(metadata);
121-
assertThat(actualContents).isEqualTo(contents);
122-
assertThat(downloader.getContentType()).isEqualTo("application/octet-stream");
120+
assertThat(actualResult).isEqualTo(metadata);
121+
assertThat(actualContents).isEqualTo(contents);
122+
assertThat(downloader.getContentType()).isEqualTo("application/octet-stream");
123+
} catch (AssertionError e) {
124+
// so subsequent tests don't fail due to file not being cleaned up
125+
client.files().deleteV2(path).getMetadata();
126+
throw e;
127+
}
123128

124129
Metadata deleted = client.files().deleteV2(path).getMetadata();
125130
assertThat(deleted).isEqualTo(metadata);

0 commit comments

Comments
 (0)