【发布时间】:2020-01-18 09:59:29
【问题描述】:
我正在尝试使用 Jest 运行示例测试以验证我的 Google Cloud 功能是否正常工作,但我不断收到以下错误。
我曾尝试直接在 windows power shell 中运行以下命令,但仍然出现相同的错误,可以在双引号前使用 \ 进行转义。
Error: Command failed: gcloud beta functions call cf-1 --region europe-west1 --data '{"data":"eyJkYXRhIjoiMSJ9"}'
ERROR: (gcloud.beta.functions.call) Invalid value for [--data]: Is not a valid JSON: No JSON object could be decoded
测试文件
const childProcess = require('child_process');
describe('Test CF', () => {
it('print outs the error message when received JSON is blank', done => {
const msg = { data: '1' };
const encodedMsg = Buffer.from(JSON.stringify(msg)).toString('base64');
const data = JSON.stringify({ data: encodedMsg });
const executeResultOutput = childProcess.execSync(`gcloud beta functions call cf-1 --region europe-west1 --data '${data}'`).toString();
const logs = childProcess
.execSync(
`gcloud functions logs read cf-1 --region europe-west1 --execution-id ${executionIdObj}`,
)
.toString();
expect(logs).toEqual(expect.stringContaining('Error..'));
});
});
更新#1:还是同样的问题...
【问题讨论】:
-
这不能回答您的问题,但请注意,您不能从 Cloud Functions 中运行的代码调用
gcloud。 -
@JohnHanley 我的意图不是从云函数中调用 gcloud。我正在关注google 的一篇文章,该文章深入了解了测试云功能,因此我将在本地运行代码并测试部署在云中的云功能。
标签: javascript google-cloud-platform jestjs google-cloud-functions child-process