Skip to content
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

Use environment variables for Firebase emulator, if available. #55

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 0 additions & 12 deletions packages/dart_firebase_admin/firebase_admin_app_test.sh

This file was deleted.

48 changes: 26 additions & 22 deletions packages/dart_firebase_admin/test/firebase_admin_app_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dart:io';
import 'dart:async';

import 'package:dart_firebase_admin/src/app.dart';
import 'package:test/test.dart';
Expand All @@ -21,30 +21,34 @@ void main() {

test(
'useEmulator() uses environment variables to set apiHost to the emulator',
() {
assert(Platform.environment['FIREBASE_AUTH_EMULATOR_HOST'] != null,
'FIREBASE_AUTH_EMULATOR_HOST is not set');
assert(Platform.environment['FIRESTORE_EMULATOR_HOST'] != null,
'FIRESTORE_EMULATOR_HOST is not set');
final firebaseAuthEmulatorHost =
Platform.environment['FIREBASE_AUTH_EMULATOR_HOST']!;
final firestoreEmulatorHost =
Platform.environment['FIRESTORE_EMULATOR_HOST']!;
() async {
const firebaseAuthEmulatorHost = '127.0.0.1:9000';
const firestoreEmulatorHost = '127.0.0.1:8000';
final testEnv = <String, String>{
'FIREBASE_AUTH_EMULATOR_HOST': firebaseAuthEmulatorHost,
'FIRESTORE_EMULATOR_HOST': firestoreEmulatorHost,
};

final app = FirebaseAdminApp.initializeApp(
'dart-firebase-admin',
Credential.fromApplicationDefaultCredentials(),
);
await runZoned(
() async {
final app = FirebaseAdminApp.initializeApp(
'dart-firebase-admin',
Credential.fromApplicationDefaultCredentials(),
);

app.useEmulator();
app.useEmulator();

expect(
app.authApiHost,
Uri.http(firebaseAuthEmulatorHost, 'identitytoolkit.googleapis.com/'),
);
expect(
app.firestoreApiHost,
Uri.http(firestoreEmulatorHost, '/'),
expect(
app.authApiHost,
Uri.http(
firebaseAuthEmulatorHost, 'identitytoolkit.googleapis.com/'),
);
expect(
app.firestoreApiHost,
Uri.http(firestoreEmulatorHost, '/'),
);
},
zoneValues: {envSymbol: testEnv},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move that before the callback, for more readable code

Copy link
Author

Choose a reason for hiding this comment

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

Resolved. Any other feedback?

);
});
});
Expand Down