firebase-realtime-database - 将 firebase-functions-test 与模拟器一起使用
问题描述
我正在尝试为我的 CI 创建一个自动化测试,将我的云功能与本地模拟器连接起来。我正在使用 firebase-functions-test 和 firebase-admin sdk。虽然我的测试在本地通过,但在使用测试 docker 容器时会失败。我创建了一个测试来说明。
const databaseName = 'foo';
const test = require('firebase-functions-test')({
databaseURL: "http://localhost:9000?ns=" + databaseName
});
describe('test', () => {
it('tests', async () => {
const admin = require('firebase-admin')
admin.initializeApp();
return await admin.database().ref('bar').push('baz')
})
})
上面的测试会反复发出警告:
@firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal metadata.google.internal:80. Error code: ENOTFOUND\"."}
我怀疑它与~/.config/gcloud/application_default_credentials.json
,但我真的不明白为什么模拟器会检查 gcloud 凭据。
任何建议表示赞赏,在此先感谢您!
解决方案
推荐阅读
- python - 如何从源代码将软件包安装到 conda env
- ansible - Ansible:使用 item.key 和 item.value 将列表合并到新列表
- reactjs - 新存储库意外添加其他文件
- c# - 如何捕获特定异常?
- javascript - Firebase 实时数据库正在为移动设备返回 permission_denied,但不是桌面设备
- css - 有没有办法让 Atom 突出显示整个软包装线?
- c - 在 macOS Catalina 上使用 gcc 和 -m32 标志编译 C
- javascript - 默认情况下,引导侧边栏无法旋转选定的项目插入符号图标
- php - 如何将ajax变量值传递给php页面?
- c# - 错误 CS1503:参数 1:无法从“UnityEngine.XR.XRNode”转换为“字符串”