Skip to content

Splitting into pre and post proguard tests #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions ci/fireci/fireci/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,34 @@
help='GRADLE_OPTS passed to the gradle invocation.')
@ci_command('gradle')
def gradle_command(task, gradle_opts):
"""Runs the specified gradle commands."""
gradle.run(*task, gradle_opts=gradle_opts)
"""Runs the specified gradle commands."""
gradle.run(*task, gradle_opts=gradle_opts)


@ci_command()
def smoke_tests_experimental():
"""Builds all SDKs in release mode and then tests test-apps against them."""
gradle.run('publishAllToBuildDir')

cwd = os.getcwd()
gradle.run(
'connectedReleaseAndroidTest',
gradle_opts='-Dmaven.repo.local={}'.format(
os.path.join(cwd, 'build', 'm2repository')),
workdir=os.path.join(cwd, 'test-apps'),
)
def smoke_tests_proguarded_app():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both tasks look almost identical, did you consider having a single parameterized smoke_tests command with a @click.option('--build-type')?

"""Builds all SDKs in release mode and then tests test-apps against them."""
gradle.run('publishAllToBuildDir')

cwd = os.getcwd()
gradle.run(
'connectedCheck',
'-PtestBuildType=release',
gradle_opts='-Dmaven.repo.local={}'.format(
os.path.join(cwd, 'build', 'm2repository')),
workdir=os.path.join(cwd, 'test-apps'),
)

@ci_command()
def smoke_tests_unproguarded_app():
"""Builds all SDKs in release mode and then tests test-apps against them."""
gradle.run('publishAllToBuildDir')

cwd = os.getcwd()
gradle.run(
'connectedCheck',
'-PtestBuildType=debug',
gradle_opts='-Dmaven.repo.local={}'.format(
os.path.join(cwd, 'build', 'm2repository')),
workdir=os.path.join(cwd, 'test-apps'),
)
204 changes: 125 additions & 79 deletions ci/fireci/tests/integ_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,82 +29,128 @@


class CliInvocationTests(unittest.TestCase):
runner = CliRunner()

@in_tempdir
def test_gradle_invocation(self):
args = ['--arg1', 'task1']
create_artifacts(
Artifact(
'gradlew',
content=scripts.with_expected_arguments_and_artifacts(
['./gradlew'] + args,
{'GRADLE_OPTS': 'opts'},
('sdk1/build/output/file1', 'content1'),
('sdk1/build/outputss/file2', 'content2'),
),
mode=0o744))
result = self.runner.invoke(cli, [
'--artifact-patterns', '**/build/output', 'gradle', '--gradle-opts',
'opts', '--'
] + args)
self.assertEqual(result.exit_code, 0)

artifacts = pathlib.Path('_artifacts')
self.assertTrue(artifacts.exists())

output_file = artifacts / 'sdk1_build_outputss' / 'file2'
self.assertFalse(output_file.exists())

output_file = artifacts / 'sdk1_build_output' / 'file1'
self.assertTrue(output_file.is_file())

with output_file.open() as f:
self.assertEqual(f.read(), 'content1')

@in_tempdir
def test_smoke_test_when_build_fails_should_fail(self):
create_artifacts(
Artifact('gradlew', content=scripts.with_exit(1), mode=0o744))
result = self.runner.invoke(cli, ['smoke_tests_experimental'])
self.assertNotEqual(result.exit_code, 0)

@in_tempdir
def test_smoke_test_when_build_succeeds_and_tests_fails_should_fail(self):
create_artifacts(
Artifact('gradlew', content=scripts.with_exit(0), mode=0o744),
Artifact('test-apps/gradlew', content=scripts.with_exit(1), mode=0o744),
)
result = self.runner.invoke(cli, ['smoke_tests_experimental'])
self.assertNotEqual(result.exit_code, 0)

@in_tempdir
def test_smoke_test_when_build_succeeds_and_tests_succeed_should_succeed(
self):
create_artifacts(
Artifact('gradlew', content=scripts.with_exit(0), mode=0o744),
Artifact('test-apps/gradlew', content=scripts.with_exit(0), mode=0o744),
)
result = self.runner.invoke(cli, ['smoke_tests_experimental'])
self.assertEqual(result.exit_code, 0)

@in_tempdir
def test_smoke_test_should_invoke_gradle_with_expected_arguments(self):
create_artifacts(
Artifact(
'gradlew',
content=scripts.with_expected_arguments(
['./gradlew', 'publishAllToBuildDir']),
mode=0o744),
Artifact(
'test-apps/gradlew',
content=scripts.with_expected_arguments(
['./gradlew', 'connectedReleaseAndroidTest'], {
'GRADLE_OPTS':
'-Dmaven.repo.local={}'.format(
os.path.join(os.getcwd(), 'build', 'm2repository'))
}),
mode=0o744),
)
result = self.runner.invoke(cli, ['smoke_tests_experimental'])
self.assertEqual(result.exit_code, 0)
runner = CliRunner()

@in_tempdir
def test_gradle_invocation(self):
args = ['--arg1', 'task1']
create_artifacts(
Artifact(
'gradlew',
content=scripts.with_expected_arguments_and_artifacts(
['./gradlew'] + args,
{'GRADLE_OPTS': 'opts'},
('sdk1/build/output/file1', 'content1'),
('sdk1/build/outputss/file2', 'content2'),
),
mode=0o744))
result = self.runner.invoke(cli, [
'--artifact-patterns', '**/build/output', 'gradle', '--gradle-opts',
'opts', '--'
] + args)
self.assertEqual(result.exit_code, 0)

artifacts = pathlib.Path('_artifacts')
self.assertTrue(artifacts.exists())

output_file = artifacts / 'sdk1_build_outputss' / 'file2'
self.assertFalse(output_file.exists())

output_file = artifacts / 'sdk1_build_output' / 'file1'
self.assertTrue(output_file.is_file())

with output_file.open() as f:
self.assertEqual(f.read(), 'content1')

@in_tempdir
def test_smoke_test_proguarded_app_when_build_fails_should_fail(self):
create_artifacts(
Artifact('gradlew', content=scripts.with_exit(1), mode=0o744))
result = self.runner.invoke(cli, ['smoke_tests_proguarded_app'])
self.assertNotEqual(result.exit_code, 0)

@in_tempdir
def test_smoke_test_proguarded_app_when_build_succeeds_and_tests_fails_should_fail(self):
create_artifacts(
Artifact('gradlew', content=scripts.with_exit(0), mode=0o744),
Artifact('test-apps/gradlew', content=scripts.with_exit(1), mode=0o744),
)
result = self.runner.invoke(cli, ['smoke_tests_proguarded_app'])
self.assertNotEqual(result.exit_code, 0)

@in_tempdir
def test_smoke_test_proguarded_app_when_build_succeeds_and_tests_succeed_should_succeed(self):
create_artifacts(
Artifact('gradlew', content=scripts.with_exit(0), mode=0o744),
Artifact('test-apps/gradlew', content=scripts.with_exit(0), mode=0o744),
)
result = self.runner.invoke(cli, ['smoke_tests_proguarded_app'])
self.assertEqual(result.exit_code, 0)

@in_tempdir
def test_smoke_test_proguarded_app_should_invoke_gradle_with_expected_arguments(self):
create_artifacts(
Artifact(
'gradlew',
content=scripts.with_expected_arguments(
['./gradlew', 'publishAllToBuildDir']),
mode=0o744),
Artifact(
'test-apps/gradlew',
content=scripts.with_expected_arguments(
['./gradlew', 'connectedCheck', '-PtestBuildType=release'], {
'GRADLE_OPTS':
'-Dmaven.repo.local={}'.format(
os.path.join(os.getcwd(), 'build', 'm2repository'))
}),
mode=0o744),
)
result = self.runner.invoke(cli, ['smoke_tests_proguarded_app'])
self.assertEqual(result.exit_code, 0)

@in_tempdir
def test_smoke_test_unproguarded_app_when_build_fails_should_fail(self):
create_artifacts(
Artifact('gradlew', content=scripts.with_exit(1), mode=0o744))
result = self.runner.invoke(cli, ['smoke_tests_unproguarded_app'])
self.assertNotEqual(result.exit_code, 0)

@in_tempdir
def test_smoke_test_unproguarded_app_when_build_succeeds_and_tests_fails_should_fail(self):
create_artifacts(
Artifact('gradlew', content=scripts.with_exit(0), mode=0o744),
Artifact('test-apps/gradlew', content=scripts.with_exit(1), mode=0o744),
)
result = self.runner.invoke(cli, ['smoke_tests_unproguarded_app'])
self.assertNotEqual(result.exit_code, 0)

@in_tempdir
def test_smoke_test_unproguarded_app_when_build_succeeds_and_tests_succeed_should_succeed(self):
create_artifacts(
Artifact('gradlew', content=scripts.with_exit(0), mode=0o744),
Artifact('test-apps/gradlew', content=scripts.with_exit(0), mode=0o744),
)
result = self.runner.invoke(cli, ['smoke_tests_unproguarded_app'])
self.assertEqual(result.exit_code, 0)

@in_tempdir
def test_smoke_test_unproguarded_app_should_invoke_gradle_with_expected_arguments(self):
create_artifacts(
Artifact(
'gradlew',
content=scripts.with_expected_arguments(
['./gradlew', 'publishAllToBuildDir']),
mode=0o744),
Artifact(
'test-apps/gradlew',
content=scripts.with_expected_arguments(
['./gradlew', 'connectedCheck', '-PtestBuildType=debug'], {
'GRADLE_OPTS':
'-Dmaven.repo.local={}'.format(
os.path.join(os.getcwd(), 'build', 'm2repository'))
}),
mode=0o744),
)
result = self.runner.invoke(cli, ['smoke_tests_unproguarded_app'])
self.assertEqual(result.exit_code, 0)

2 changes: 1 addition & 1 deletion test-apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ This experimental directory contains apps that are used to smoke test Firebase A
- From the /test-apps dir, run the tests

```
./gradlew connectedReleaseAndroidTest -PfirebaseProjectId=<your_project_id> -PfirebaseToken=<your_firebase_token> -Pm2Repository=${PWD}/../build/m2repository/
./gradlew connectedCheck -PtestBuildType=<release|debug> -PfirebaseProjectId=<your_project_id> -PfirebaseToken=<your_firebase_token> -Pm2Repository=${PWD}/../build/m2repository/
```
8 changes: 6 additions & 2 deletions test-apps/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ buildscript {
jcenter()
mavenLocal()
google()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
Expand All @@ -38,6 +37,8 @@ plugins {
}

allprojects {
ext.testBuildType = project.getProperties().get("testBuildType", "debug")

apply plugin: 'com.github.sherter.google-java-format'
googleJavaFormat {
toolVersion = '1.6'
Expand Down Expand Up @@ -71,6 +72,9 @@ allprojects {
if ( it.name == 'processReleaseGoogleServices') {
it.dependsOn 'copyRootGoogleServices'
}
if ( it.name == 'processDebugGoogleServices') {
it.dependsOn 'copyRootGoogleServices'
}
}

if(file('test_setup.sh').exists()) {
Expand Down Expand Up @@ -118,7 +122,7 @@ allprojects {
}
}
tasks.whenTaskAdded {
if ( it.name == 'connectedReleaseAndroidTest') {
if ( it.name == 'connectedCheck') {
it.dependsOn setupSmokeTest
it.dependsOn rootProject.tasks.findByName("dependencyUpdates")
}
Expand Down
2 changes: 1 addition & 1 deletion test-apps/database-test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
apply plugin: 'com.android.application'

android {
testBuildType "release"
testBuildType = project.testBuildType
compileSdkVersion 27

defaultConfig {
Expand Down
2 changes: 1 addition & 1 deletion test-apps/firestore-test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
apply plugin: 'com.android.application'

android {
testBuildType "release"
testBuildType = project.testBuildType
compileSdkVersion 27

defaultConfig {
Expand Down
3 changes: 1 addition & 2 deletions test-apps/functions-test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
apply plugin: 'com.android.application'

android {
// Changes the test build type for instrumented tests to "stage".
testBuildType "release"
testBuildType = project.testBuildType
compileSdkVersion 27

defaultConfig {
Expand Down
2 changes: 1 addition & 1 deletion test-apps/storage-test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
apply plugin: 'com.android.application'

android {
testBuildType "release"
testBuildType = project.testBuildType
compileSdkVersion 27

defaultConfig {
Expand Down