Skip to content

Commit e9de41d

Browse files
authored
Loading the API key from a local file instead of a command-line arg (#25)
1 parent 297f935 commit e9de41d

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ node_modules/
1010

1111
# Real key file should not be checked in
1212
test/resources/key.json
13+
test/resources/apikey.txt
1314

1415
# Release tarballs should not be checked in
1516
firebase-admin-*.tgz

CONTRIBUTING.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,16 @@ $ gulp # Lint, build, and run unit test suite
134134
To run the integration test suite:
135135

136136
```
137-
$ node test/integration <apiKey> # Run integration test suite
137+
$ node test/integration # Run integration test suite
138138
```
139139

140-
The integration test suite requires you to generate a service account key JSON file for a
141-
Firebase project and save it to `test/resources/key.json`. Create a new project in the
142-
[Firebase console](https://console.firebase.google.com) if you do not already have one.
143-
Use a separate, dedicated project for integration tests since the test suite makes a large
144-
number of writes to the Firebase realtime database. Download the service account key file
145-
from the "Settings > Service Accounts" page of the project, and copy it to
146-
`test/resources/key.json`. Also obtain the API key for the same project from "Settings > General".
147-
This API key should be passed into the test suite as a command-line argument.
140+
The integration test suite requires a service account JSON key file, and an API key for a Firebase
141+
project. Create a new project in the [Firebase console](https://console.firebase.google.com) if
142+
you do not already have one. Use a separate, dedicated project for integration tests since the
143+
test suite makes a large number of writes to the Firebase realtime database. Download the service
144+
account key file from the "Settings > Service Accounts" page of the project, and copy it to
145+
`test/resources/key.json`. Also obtain the API key for the same project from "Settings > General",
146+
and save it to `test/resource/apikey.txt`.
148147

149148
### Repo Organization
150149

test/integration/utils.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
var _ = require('lodash');
1818
var chalk = require('chalk');
19+
var fs = require('fs');
20+
var path = require('path');
1921

2022
var failureCount = 0;
2123
var successCount = 0;
@@ -36,11 +38,16 @@ try {
3638
process.exit(1);
3739
}
3840

39-
var apiKey = process.argv[2];
40-
if (typeof apiKey === 'undefined') {
41+
var apiKey;
42+
43+
try {
44+
apiKey = fs.readFileSync(path.join(__dirname, '../resources/apikey.txt'))
45+
} catch (error) {
4146
console.log(chalk.red(
4247
'The integration test suite requires an API key for a ' +
43-
'Firebase project to be specified as a command-line argument.'));
48+
'Firebase project to be saved to `test/resources/apikey.txt`.',
49+
error
50+
));
4451
process.exit(1);
4552
}
4653

0 commit comments

Comments
 (0)