Skip to content

@invertase/rebased v2 integration tests #1718

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

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
steps:
- name: "node:18"
id: "Install dependencies"
dir: "integration_test"
entrypoint: "npm"
args: ["install"]
- name: "node:18"
id: "Set Project ID"
dir: "integration_test"
entrypoint: "npx"
args: ["firebase", "use", "cf3-integration-tests-d7be6"]
- name: "node:18"
id: "Run tests"
dir: "integration_test"
entrypoint: "npm"
args: ["start"]

options:
defaultLogsBucketBehavior: REGIONAL_USER_OWNED_BUCKET
13 changes: 13 additions & 0 deletions integration_test/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DEBUG=true
TEST_RUNTIME=node
REGION=us-central1
PROJECT_ID=
DATABASE_URL=
STORAGE_BUCKET=
NODE_VERSION=18
FIREBASE_ADMIN=^12.6.0
FIREBASE_APP_ID=
FIREBASE_MEASUREMENT_ID=
FIREBASE_AUTH_DOMAIN=
FIREBASE_API_KEY=
GOOGLE_ANALYTICS_API_SECRET=
75 changes: 75 additions & 0 deletions integration_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Firebase/GCP config
.firebaserc
serviceAccount.json
functions.yaml
functions/src/package.json
functions/package/

.nvmrc
44 changes: 31 additions & 13 deletions integration_test/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
## How to Use
# Integration Test Suite

**_ATTENTION_**: Running this test will wipe the contents of the Firebase project(s) you run it against. Make sure you use disposable Firebase project(s)!
## How to use

Run the integration test as follows:
### Prerequisites

Tests use locally installed firebase to invoke commands for deploying functions.
The tests also require that you have gcloud CLI installed and authenticated
(`gcloud auth login`).

Tests are deployed with a unique identifier, which enables the teardown of its own resources, without affecting other test runs.

1. Add a service account at root serviceAccount.json
2. Add a .env `cp .env.example .env`
3. Ensure service account has required roles for each cloud service
4. Ensure any resources such as eventarc channel ("firebase" is used as default) are configured

### Running setup and tests

This will deploy functions with unique names, set up environment for running the jest files, and run the jest test suite.

```bash
./run_tests.sh <project_id> [<project_id2>]
yarn start
```

Test runs cycles of testing, once for Node.js 14 and another for Node.js 16.

Test uses locally installed firebase to invoke commands for deploying function. The test also requires that you have
gcloud CLI installed and authenticated (`gcloud auth login`).
## TODO

Integration test is triggered by invoking HTTP function integrationTest which in turns invokes each function trigger
by issuing actions necessary to trigger it (e.g. write to storage bucket).
[x] Deploy functions with unique name
[x] Update existing tests to use jest (v1 and v2)
[x] Add missing coverage for v1 and v2 (WIP)
[x] Ensure proper teardown of resources (only those for current test run)
[] Analytics: since you cannot directly trigger onLog events from Firebase Analytics in a CI environment, the primary strategy is to isolate and test the logic within the Cloud Functions by mocking Firebase services and the Analytics event data. This is done elsewhere via unit tests, so no additional coverage added.
[] Alerts: same as analytics, couldn't find way to trigger.
[] Auth blocking functions can only be deployed one at a time, half-way solution is to deploy v1 functions, run v1 tests, teardown, and repeat for v2. However, this still won't allow for multiple runs to happen in parallel. Solution needed before re-enabling auth/identity tests. You can run the suite with either v1 or v2 commented out to check test runs.
[] Https tests were commented out previously, comments remain as before
[] Python runtime support

### Debugging
## Troubleshooting

The status and result of each test is stored in RTDB of the project used for testing. You can also inspect Cloud Logging
for more clues.
- Sometimes I ran into this reported [issue](https://github.com/firebase/firebase-tools/issues/793), I had to give it some period of time and attempt deploy again. Probably an upstream issue but may affect our approach here. Seems to struggle with deploying the large amount of trigger functions...? Falls over on Firebase Storage functions (if you comment these out everything else deploys as expected).
3 changes: 1 addition & 2 deletions integration_test/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
},
"functions": {
"source": "functions",
"codebase": "integration-tests",
"predeploy": ["npm --prefix \"$RESOURCE_DIR\" run build"]
"codebase": "integration-tests"
}
}
Loading