mirror of
https://github.com/zhigang1992/firebase-tools.git
synced 2026-01-12 22:47:24 +08:00
Switch from outdated ESLint to Prettier (#731)
This commit is contained in:
@@ -1,31 +1,37 @@
|
||||
var functions = require('firebase-functions');
|
||||
var admin = require('firebase-admin');
|
||||
var functions = require("firebase-functions");
|
||||
var admin = require("firebase-admin");
|
||||
admin.initializeApp(functions.config().firebase);
|
||||
|
||||
exports.dbAction = functions.database.ref('/input/{uuid}').onWrite(function(event) {
|
||||
console.log('Received event:', event);
|
||||
return event.data.ref.root.child('output/' + event.params.uuid).set(event.data.val());
|
||||
exports.dbAction = functions.database.ref("/input/{uuid}").onWrite(function(event) {
|
||||
console.log("Received event:", event);
|
||||
return event.data.ref.root.child("output/" + event.params.uuid).set(event.data.val());
|
||||
});
|
||||
|
||||
exports.nested = {
|
||||
dbAction: functions.database.ref('/inputNested/{uuid}').onWrite(function(event) {
|
||||
console.log('Received event:', event);
|
||||
return event.data.ref.root.child('output/' + event.params.uuid).set(event.data.val());
|
||||
})
|
||||
dbAction: functions.database.ref("/inputNested/{uuid}").onWrite(function(event) {
|
||||
console.log("Received event:", event);
|
||||
return event.data.ref.root.child("output/" + event.params.uuid).set(event.data.val());
|
||||
}),
|
||||
};
|
||||
|
||||
exports.httpsAction = functions.https.onRequest(function(req, res) {
|
||||
res.send(req.body);
|
||||
});
|
||||
|
||||
exports.pubsubAction = functions.pubsub.topic('topic1').onPublish(function(event) {
|
||||
console.log('Received event:', event);
|
||||
exports.pubsubAction = functions.pubsub.topic("topic1").onPublish(function(event) {
|
||||
console.log("Received event:", event);
|
||||
var uuid = event.data.json;
|
||||
return admin.database().ref('output/' + uuid).set(uuid);
|
||||
return admin
|
||||
.database()
|
||||
.ref("output/" + uuid)
|
||||
.set(uuid);
|
||||
});
|
||||
|
||||
exports.gcsAction = functions.storage.object().onChange(function(event) {
|
||||
console.log('Received event:', event);
|
||||
console.log("Received event:", event);
|
||||
var uuid = event.data.name;
|
||||
return admin.database().ref('output/' + uuid).set(uuid);
|
||||
return admin
|
||||
.database()
|
||||
.ref("output/" + uuid)
|
||||
.set(uuid);
|
||||
});
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
var chalk = require('chalk');
|
||||
var exec = require('child_process').exec;
|
||||
var expect = require('chai').expect;
|
||||
var fs = require('fs-extra');
|
||||
var tmp = require('tmp');
|
||||
var RSVP = require('rsvp');
|
||||
var chalk = require("chalk");
|
||||
var exec = require("child_process").exec;
|
||||
var expect = require("chai").expect;
|
||||
var fs = require("fs-extra");
|
||||
var tmp = require("tmp");
|
||||
var RSVP = require("rsvp");
|
||||
|
||||
var api = require('../lib/api');
|
||||
var scopes = require('../lib/scopes');
|
||||
var configstore = require('../lib/configstore');
|
||||
var api = require("../lib/api");
|
||||
var scopes = require("../lib/scopes");
|
||||
var configstore = require("../lib/configstore");
|
||||
|
||||
var localFirebase = __dirname + '/../bin/firebase';
|
||||
var projectDir = __dirname + '/test-project';
|
||||
var localFirebase = __dirname + "/../bin/firebase";
|
||||
var projectDir = __dirname + "/test-project";
|
||||
var tmpDir;
|
||||
|
||||
var preTest = function() {
|
||||
var dir = tmp.dirSync({prefix: 'cfgtest_'});
|
||||
var dir = tmp.dirSync({ prefix: "cfgtest_" });
|
||||
tmpDir = dir.name;
|
||||
fs.copySync(projectDir, tmpDir);
|
||||
api.setRefreshToken(configstore.get('tokens').refresh_token);
|
||||
api.setRefreshToken(configstore.get("tokens").refresh_token);
|
||||
api.setScopes(scopes.CLOUD_PLATFORM);
|
||||
console.log('Done pretest prep.');
|
||||
console.log("Done pretest prep.");
|
||||
};
|
||||
|
||||
var postTest = function() {
|
||||
fs.remove(tmpDir);
|
||||
console.log('Done post-test cleanup.');
|
||||
console.log("Done post-test cleanup.");
|
||||
};
|
||||
|
||||
var set = function(expression) {
|
||||
return new RSVP.Promise(function(resolve) {
|
||||
exec(localFirebase + ' functions:config:set ' + expression, {'cwd': tmpDir}, function(err) {
|
||||
exec(localFirebase + " functions:config:set " + expression, { cwd: tmpDir }, function(err) {
|
||||
expect(err).to.be.null;
|
||||
resolve();
|
||||
});
|
||||
@@ -41,7 +41,7 @@ var set = function(expression) {
|
||||
|
||||
var unset = function(key) {
|
||||
return new RSVP.Promise(function(resolve) {
|
||||
exec(localFirebase + ' functions:config:unset ' + key, {'cwd': tmpDir}, function(err) {
|
||||
exec(localFirebase + " functions:config:unset " + key, { cwd: tmpDir }, function(err) {
|
||||
expect(err).to.be.null;
|
||||
resolve();
|
||||
});
|
||||
@@ -50,7 +50,7 @@ var unset = function(key) {
|
||||
|
||||
var getAndCompare = function(expected) {
|
||||
return new RSVP.Promise(function(resolve) {
|
||||
exec(localFirebase + ' functions:config:get', {'cwd': tmpDir}, function(err, stdout) {
|
||||
exec(localFirebase + " functions:config:get", { cwd: tmpDir }, function(err, stdout) {
|
||||
expect(JSON.parse(stdout)).to.deep.equal(expected);
|
||||
resolve();
|
||||
});
|
||||
@@ -59,36 +59,60 @@ var getAndCompare = function(expected) {
|
||||
|
||||
var runTest = function(description, expression, key, expected) {
|
||||
return set(expression)
|
||||
.then(function() {
|
||||
return getAndCompare(expected);
|
||||
}).then(function() {
|
||||
return unset(key);
|
||||
}).then(function() {
|
||||
console.log(chalk.green('\u2713 Test passed: ') + description);
|
||||
});
|
||||
.then(function() {
|
||||
return getAndCompare(expected);
|
||||
})
|
||||
.then(function() {
|
||||
return unset(key);
|
||||
})
|
||||
.then(function() {
|
||||
console.log(chalk.green("\u2713 Test passed: ") + description);
|
||||
});
|
||||
};
|
||||
|
||||
var main = function() {
|
||||
preTest();
|
||||
runTest('string value', 'foo.bar=faz', 'foo', {foo: {bar: 'faz'}})
|
||||
.then(function() {
|
||||
return runTest('string value in quotes', 'foo.bar="faz"', 'foo', {foo: {bar: 'faz'}});
|
||||
}).then(function() {
|
||||
return runTest('string value with quotes', 'foo.bar=\'"faz"\'', 'foo', {foo: {bar: '\"faz\"'}});
|
||||
}).then(function() {
|
||||
return runTest('single-part key and JSON value', 'foo=\'{"bar":"faz"}\'', 'foo', {foo: {bar: 'faz'}});
|
||||
}).then(function() {
|
||||
return runTest('multi-part key and JSON value', 'foo.too=\'{"bar":"faz"}\'', 'foo', {foo: {too: {bar: 'faz'}}});
|
||||
}).then(function() {
|
||||
return runTest('numeric value', 'foo.bar=123', 'foo', {foo: {bar: '123'}});
|
||||
}).then(function() {
|
||||
return runTest('numeric value in quotes', 'foo.bar="123"', 'foo', {foo: {bar: '123'}});
|
||||
}).then(function() {
|
||||
return runTest('null value', 'foo.bar=null', 'foo', {foo: {bar: 'null'}});
|
||||
}).catch(function(err) {
|
||||
console.log(chalk.red('Error while running tests: '), err);
|
||||
return RSVP.resolve();
|
||||
}).then(postTest);
|
||||
runTest("string value", "foo.bar=faz", "foo", { foo: { bar: "faz" } })
|
||||
.then(function() {
|
||||
return runTest("string value in quotes", 'foo.bar="faz"', "foo", {
|
||||
foo: { bar: "faz" },
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
return runTest("string value with quotes", "foo.bar='\"faz\"'", "foo", {
|
||||
foo: { bar: '"faz"' },
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
return runTest("single-part key and JSON value", 'foo=\'{"bar":"faz"}\'', "foo", {
|
||||
foo: { bar: "faz" },
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
return runTest("multi-part key and JSON value", 'foo.too=\'{"bar":"faz"}\'', "foo", {
|
||||
foo: { too: { bar: "faz" } },
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
return runTest("numeric value", "foo.bar=123", "foo", {
|
||||
foo: { bar: "123" },
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
return runTest("numeric value in quotes", 'foo.bar="123"', "foo", {
|
||||
foo: { bar: "123" },
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
return runTest("null value", "foo.bar=null", "foo", {
|
||||
foo: { bar: "null" },
|
||||
});
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log(chalk.red("Error while running tests: "), err);
|
||||
return RSVP.resolve();
|
||||
})
|
||||
.then(postTest);
|
||||
};
|
||||
|
||||
main();
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
var expect = require('chai').expect;
|
||||
var execSync = require('child_process').execSync;
|
||||
var exec = require('child_process').exec;
|
||||
var tmp = require('tmp');
|
||||
var _ = require('lodash');
|
||||
var fs = require('fs-extra');
|
||||
var cloudfunctions = require('../lib/gcp/cloudfunctions');
|
||||
var api = require('../lib/api');
|
||||
var scopes = require('../lib/scopes');
|
||||
var configstore = require('../lib/configstore');
|
||||
var extractTriggers = require('../lib/extractTriggers');
|
||||
var RSVP = require('rsvp');
|
||||
var chalk = require('chalk');
|
||||
var firebase = require('firebase');
|
||||
var functions = require('firebase-functions');
|
||||
var admin = require('firebase-admin');
|
||||
var sinon = require('sinon');
|
||||
var expect = require("chai").expect;
|
||||
var execSync = require("child_process").execSync;
|
||||
var exec = require("child_process").exec;
|
||||
var tmp = require("tmp");
|
||||
var _ = require("lodash");
|
||||
var fs = require("fs-extra");
|
||||
var cloudfunctions = require("../lib/gcp/cloudfunctions");
|
||||
var api = require("../lib/api");
|
||||
var scopes = require("../lib/scopes");
|
||||
var configstore = require("../lib/configstore");
|
||||
var extractTriggers = require("../lib/extractTriggers");
|
||||
var RSVP = require("rsvp");
|
||||
var chalk = require("chalk");
|
||||
var firebase = require("firebase");
|
||||
var functions = require("firebase-functions");
|
||||
var admin = require("firebase-admin");
|
||||
var sinon = require("sinon");
|
||||
|
||||
var functionsSource = __dirname + '/assets/functions_to_test.js';
|
||||
var projectDir = __dirname + '/test-project';
|
||||
var projectId = 'functions-integration-test';
|
||||
var httpsTrigger = 'https://us-central1-functions-integration-test.cloudfunctions.net/httpsAction';
|
||||
var region = 'us-central1';
|
||||
var localFirebase = __dirname + '/../bin/firebase';
|
||||
var functionsSource = __dirname + "/assets/functions_to_test.js";
|
||||
var projectDir = __dirname + "/test-project";
|
||||
var projectId = "functions-integration-test";
|
||||
var httpsTrigger = "https://us-central1-functions-integration-test.cloudfunctions.net/httpsAction";
|
||||
var region = "us-central1";
|
||||
var localFirebase = __dirname + "/../bin/firebase";
|
||||
var TIMEOUT = 40000;
|
||||
var tmpDir;
|
||||
var app;
|
||||
|
||||
var parseFunctionsList = function() {
|
||||
var configStub = sinon.stub(functions, 'config').returns({
|
||||
var configStub = sinon.stub(functions, "config").returns({
|
||||
firebase: {
|
||||
databaseURL: 'https://not-a-project.firebaseio.com',
|
||||
storageBucket: 'not-a-project.appspot.com'
|
||||
}
|
||||
databaseURL: "https://not-a-project.firebaseio.com",
|
||||
storageBucket: "not-a-project.appspot.com",
|
||||
},
|
||||
});
|
||||
var adminStub = sinon.stub(admin, 'initializeApp');
|
||||
var adminStub = sinon.stub(admin, "initializeApp");
|
||||
var triggers = [];
|
||||
extractTriggers(require(functionsSource), triggers);
|
||||
configStub.restore();
|
||||
adminStub.restore();
|
||||
return _.map(triggers, 'name');
|
||||
return _.map(triggers, "name");
|
||||
};
|
||||
|
||||
var getUuid = function() {
|
||||
@@ -49,43 +49,46 @@ var getUuid = function() {
|
||||
};
|
||||
|
||||
var preTest = function() {
|
||||
var dir = tmp.dirSync({prefix: 'fntest_'});
|
||||
var dir = tmp.dirSync({ prefix: "fntest_" });
|
||||
tmpDir = dir.name;
|
||||
fs.copySync(projectDir, tmpDir);
|
||||
execSync('npm install', {'cwd': tmpDir + '/functions'});
|
||||
api.setRefreshToken(configstore.get('tokens').refresh_token);
|
||||
execSync("npm install", { cwd: tmpDir + "/functions" });
|
||||
api.setRefreshToken(configstore.get("tokens").refresh_token);
|
||||
api.setScopes(scopes.CLOUD_PLATFORM);
|
||||
var config = {
|
||||
apiKey: 'AIzaSyCLgng7Qgzf-2UKRPLz--LtLLxUsMK8oco',
|
||||
authDomain: 'functions-integration-test.firebaseapp.com',
|
||||
databaseURL: 'https://functions-integration-test.firebaseio.com',
|
||||
storageBucket: 'functions-integration-test.appspot.com'
|
||||
apiKey: "AIzaSyCLgng7Qgzf-2UKRPLz--LtLLxUsMK8oco",
|
||||
authDomain: "functions-integration-test.firebaseapp.com",
|
||||
databaseURL: "https://functions-integration-test.firebaseio.com",
|
||||
storageBucket: "functions-integration-test.appspot.com",
|
||||
};
|
||||
app = firebase.initializeApp(config);
|
||||
console.log('Done pretest prep.');
|
||||
console.log("Done pretest prep.");
|
||||
};
|
||||
|
||||
var postTest = function() {
|
||||
fs.remove(tmpDir);
|
||||
execSync(localFirebase + ' database:remove / -y', {'cwd': tmpDir});
|
||||
console.log('Done post-test cleanup.');
|
||||
execSync(localFirebase + " database:remove / -y", { cwd: tmpDir });
|
||||
console.log("Done post-test cleanup.");
|
||||
process.exit();
|
||||
};
|
||||
|
||||
var checkFunctionsListMatch = function(expectedFunctions) {
|
||||
return cloudfunctions.list(projectId, region).then(function(result) {
|
||||
var deployedFunctions = _.map(result, 'functionName');
|
||||
expect(_.isEmpty(_.xor(expectedFunctions, deployedFunctions))).to.be.true;
|
||||
return true;
|
||||
}).catch(function(err) {
|
||||
expect(err).to.be.null;
|
||||
});
|
||||
return cloudfunctions
|
||||
.list(projectId, region)
|
||||
.then(function(result) {
|
||||
var deployedFunctions = _.map(result, "functionName");
|
||||
expect(_.isEmpty(_.xor(expectedFunctions, deployedFunctions))).to.be.true;
|
||||
return true;
|
||||
})
|
||||
.catch(function(err) {
|
||||
expect(err).to.be.null;
|
||||
});
|
||||
};
|
||||
|
||||
var testCreateUpdate = function() {
|
||||
fs.copySync(functionsSource, tmpDir + '/functions/index.js');
|
||||
fs.copySync(functionsSource, tmpDir + "/functions/index.js");
|
||||
return new RSVP.Promise(function(resolve) {
|
||||
exec(localFirebase + ' deploy', {'cwd': tmpDir}, function(err, stdout) {
|
||||
exec(localFirebase + " deploy", { cwd: tmpDir }, function(err, stdout) {
|
||||
console.log(stdout);
|
||||
expect(err).to.be.null;
|
||||
resolve(checkFunctionsListMatch(parseFunctionsList()));
|
||||
@@ -94,19 +97,26 @@ var testCreateUpdate = function() {
|
||||
};
|
||||
|
||||
var testCreateUpdateWithFilter = function() {
|
||||
fs.copySync(functionsSource, tmpDir + '/functions/index.js');
|
||||
fs.copySync(functionsSource, tmpDir + "/functions/index.js");
|
||||
return new RSVP.Promise(function(resolve) {
|
||||
exec(localFirebase + ' deploy --only functions:dbAction,functions:httpsAction', {'cwd': tmpDir}, function(err, stdout) {
|
||||
console.log(stdout);
|
||||
expect(err).to.be.null;
|
||||
resolve(checkFunctionsListMatch(['dbAction', 'httpsAction']));
|
||||
});
|
||||
exec(
|
||||
localFirebase + " deploy --only functions:dbAction,functions:httpsAction",
|
||||
{ cwd: tmpDir },
|
||||
function(err, stdout) {
|
||||
console.log(stdout);
|
||||
expect(err).to.be.null;
|
||||
resolve(checkFunctionsListMatch(["dbAction", "httpsAction"]));
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
var testDelete = function() {
|
||||
return new RSVP.Promise(function(resolve) {
|
||||
exec('> functions/index.js &&' + localFirebase + ' deploy', {'cwd': tmpDir}, function(err, stdout) {
|
||||
exec("> functions/index.js &&" + localFirebase + " deploy", { cwd: tmpDir }, function(
|
||||
err,
|
||||
stdout
|
||||
) {
|
||||
console.log(stdout);
|
||||
expect(err).to.be.null;
|
||||
resolve(checkFunctionsListMatch([]));
|
||||
@@ -116,141 +126,180 @@ var testDelete = function() {
|
||||
|
||||
var testDeleteWithFilter = function() {
|
||||
return new RSVP.Promise(function(resolve) {
|
||||
exec('> functions/index.js &&' + localFirebase + ' deploy --only functions:dbAction', {'cwd': tmpDir}, function(err, stdout) {
|
||||
console.log(stdout);
|
||||
expect(err).to.be.null;
|
||||
resolve(checkFunctionsListMatch(['httpsAction']));
|
||||
});
|
||||
exec(
|
||||
"> functions/index.js &&" + localFirebase + " deploy --only functions:dbAction",
|
||||
{ cwd: tmpDir },
|
||||
function(err, stdout) {
|
||||
console.log(stdout);
|
||||
expect(err).to.be.null;
|
||||
resolve(checkFunctionsListMatch(["httpsAction"]));
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
var testUnknownFilter = function() {
|
||||
return new RSVP.Promise(function(resolve) {
|
||||
exec('> functions/index.js &&' + localFirebase + ' deploy --only functions:unknownFilter', {'cwd': tmpDir}, function(err, stdout) {
|
||||
console.log(stdout);
|
||||
expect(stdout).to.contain('the following filters were specified but do not match any functions in the project: unknownFilter');
|
||||
expect(err).to.be.null;
|
||||
resolve(checkFunctionsListMatch(['httpsAction']));
|
||||
});
|
||||
exec(
|
||||
"> functions/index.js &&" + localFirebase + " deploy --only functions:unknownFilter",
|
||||
{ cwd: tmpDir },
|
||||
function(err, stdout) {
|
||||
console.log(stdout);
|
||||
expect(stdout).to.contain(
|
||||
"the following filters were specified but do not match any functions in the project: unknownFilter"
|
||||
);
|
||||
expect(err).to.be.null;
|
||||
resolve(checkFunctionsListMatch(["httpsAction"]));
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
var waitForAck = function(uuid, testDescription) {
|
||||
return Promise.race([
|
||||
new Promise(function(resolve) {
|
||||
var ref = firebase.database().ref('output').child(uuid);
|
||||
var listener = ref.on('value', function(snap) {
|
||||
var ref = firebase
|
||||
.database()
|
||||
.ref("output")
|
||||
.child(uuid);
|
||||
var listener = ref.on("value", function(snap) {
|
||||
if (snap.exists()) {
|
||||
ref.off('value', listener);
|
||||
ref.off("value", listener);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}),
|
||||
new Promise(function(resolve, reject) {
|
||||
setTimeout(function() {
|
||||
reject('Timed out while waiting for output from ' + testDescription);
|
||||
reject("Timed out while waiting for output from " + testDescription);
|
||||
}, TIMEOUT);
|
||||
})
|
||||
}),
|
||||
]);
|
||||
};
|
||||
|
||||
var writeToDB = function(path) {
|
||||
var uuid = getUuid();
|
||||
return app.database().ref(path).child(uuid).set({'foo': 'bar'}).then(function() {
|
||||
return RSVP.resolve(uuid);
|
||||
});
|
||||
return app
|
||||
.database()
|
||||
.ref(path)
|
||||
.child(uuid)
|
||||
.set({ foo: "bar" })
|
||||
.then(function() {
|
||||
return RSVP.resolve(uuid);
|
||||
});
|
||||
};
|
||||
|
||||
var sendHttpRequest = function(message) {
|
||||
return api.request('POST', httpsTrigger, {
|
||||
data: message,
|
||||
origin: ''
|
||||
}).then(function(resp) {
|
||||
expect(resp.status).to.equal(200);
|
||||
expect(resp.body).to.deep.equal(message);
|
||||
});
|
||||
return api
|
||||
.request("POST", httpsTrigger, {
|
||||
data: message,
|
||||
origin: "",
|
||||
})
|
||||
.then(function(resp) {
|
||||
expect(resp.status).to.equal(200);
|
||||
expect(resp.body).to.deep.equal(message);
|
||||
});
|
||||
};
|
||||
|
||||
var publishPubsub = function(topic) {
|
||||
var uuid = getUuid();
|
||||
var message = new Buffer(uuid).toString('base64');
|
||||
return api.request('POST', '/v1/projects/functions-integration-test/topics/' + topic + ':publish', {
|
||||
auth: true,
|
||||
data: {'messages': [
|
||||
{'data': message}
|
||||
]},
|
||||
origin: 'https://pubsub.googleapis.com'
|
||||
}).then(function(resp) {
|
||||
expect(resp.status).to.equal(200);
|
||||
return RSVP.resolve(uuid);
|
||||
});
|
||||
var message = new Buffer(uuid).toString("base64");
|
||||
return api
|
||||
.request("POST", "/v1/projects/functions-integration-test/topics/" + topic + ":publish", {
|
||||
auth: true,
|
||||
data: {
|
||||
messages: [{ data: message }],
|
||||
},
|
||||
origin: "https://pubsub.googleapis.com",
|
||||
})
|
||||
.then(function(resp) {
|
||||
expect(resp.status).to.equal(200);
|
||||
return RSVP.resolve(uuid);
|
||||
});
|
||||
};
|
||||
|
||||
var saveToStorage = function() {
|
||||
var uuid = getUuid();
|
||||
var contentLength = Buffer.byteLength(uuid, 'utf8');
|
||||
var resource = ['b', projectId + '.appspot.com', 'o'].join('/');
|
||||
var endpoint = '/upload/storage/v1/' + resource + '?uploadType=media&name=' + uuid;
|
||||
return api.request('POST', endpoint, {
|
||||
auth: true,
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
'Content-Length': contentLength
|
||||
},
|
||||
data: uuid,
|
||||
json: false,
|
||||
origin: api.googleOrigin
|
||||
}).then(function(resp) {
|
||||
expect(resp.status).to.equal(200);
|
||||
return RSVP.resolve(uuid);
|
||||
});
|
||||
var contentLength = Buffer.byteLength(uuid, "utf8");
|
||||
var resource = ["b", projectId + ".appspot.com", "o"].join("/");
|
||||
var endpoint = "/upload/storage/v1/" + resource + "?uploadType=media&name=" + uuid;
|
||||
return api
|
||||
.request("POST", endpoint, {
|
||||
auth: true,
|
||||
headers: {
|
||||
"Content-Type": "text/plain",
|
||||
"Content-Length": contentLength,
|
||||
},
|
||||
data: uuid,
|
||||
json: false,
|
||||
origin: api.googleOrigin,
|
||||
})
|
||||
.then(function(resp) {
|
||||
expect(resp.status).to.equal(200);
|
||||
return RSVP.resolve(uuid);
|
||||
});
|
||||
};
|
||||
|
||||
var testFunctionsTrigger = function() {
|
||||
var checkDbAction = writeToDB('input').then(function(uuid) {
|
||||
return waitForAck(uuid, 'database triggered function');
|
||||
var checkDbAction = writeToDB("input").then(function(uuid) {
|
||||
return waitForAck(uuid, "database triggered function");
|
||||
});
|
||||
var checkNestedDbAction = writeToDB('inputNested').then(function(uuid) {
|
||||
return waitForAck(uuid, 'nested database triggered function');
|
||||
var checkNestedDbAction = writeToDB("inputNested").then(function(uuid) {
|
||||
return waitForAck(uuid, "nested database triggered function");
|
||||
});
|
||||
var checkHttpsAction = sendHttpRequest({'message': 'hello'});
|
||||
var checkPubsubAction = publishPubsub('topic1').then(function(uuid) {
|
||||
return waitForAck(uuid, 'pubsub triggered function');
|
||||
var checkHttpsAction = sendHttpRequest({ message: "hello" });
|
||||
var checkPubsubAction = publishPubsub("topic1").then(function(uuid) {
|
||||
return waitForAck(uuid, "pubsub triggered function");
|
||||
});
|
||||
var checkGcsAction = saveToStorage().then(function(uuid) {
|
||||
return waitForAck(uuid, 'storage triggered function');
|
||||
return waitForAck(uuid, "storage triggered function");
|
||||
});
|
||||
return RSVP.all([checkDbAction, checkNestedDbAction, checkHttpsAction, checkPubsubAction, checkGcsAction]);
|
||||
return RSVP.all([
|
||||
checkDbAction,
|
||||
checkNestedDbAction,
|
||||
checkHttpsAction,
|
||||
checkPubsubAction,
|
||||
checkGcsAction,
|
||||
]);
|
||||
};
|
||||
|
||||
var main = function() {
|
||||
preTest();
|
||||
testCreateUpdate().then(function() {
|
||||
console.log(chalk.green('\u2713 Test passed: creating functions'));
|
||||
return testCreateUpdate();
|
||||
}).then(function() {
|
||||
console.log(chalk.green('\u2713 Test passed: updating functions'));
|
||||
return testFunctionsTrigger();
|
||||
}).then(function() {
|
||||
console.log(chalk.green('\u2713 Test passed: triggering functions'));
|
||||
return testDelete();
|
||||
}).then(function() {
|
||||
console.log(chalk.green('\u2713 Test passed: deleting functions'));
|
||||
return testCreateUpdateWithFilter();
|
||||
}).then(function() {
|
||||
console.log(chalk.green('\u2713 Test passed: creating functions with filters'));
|
||||
return testDeleteWithFilter();
|
||||
}).then(function() {
|
||||
console.log(chalk.green('\u2713 Test passed: deleting functions with filters'));
|
||||
return testUnknownFilter();
|
||||
}).then(function() {
|
||||
console.log(chalk.green('\u2713 Test passed: threw warning when passing filter with unknown identifier'));
|
||||
}).catch(function(err) {
|
||||
console.log(chalk.red('Error while running tests: '), err);
|
||||
return RSVP.resolve();
|
||||
}).then(postTest);
|
||||
testCreateUpdate()
|
||||
.then(function() {
|
||||
console.log(chalk.green("\u2713 Test passed: creating functions"));
|
||||
return testCreateUpdate();
|
||||
})
|
||||
.then(function() {
|
||||
console.log(chalk.green("\u2713 Test passed: updating functions"));
|
||||
return testFunctionsTrigger();
|
||||
})
|
||||
.then(function() {
|
||||
console.log(chalk.green("\u2713 Test passed: triggering functions"));
|
||||
return testDelete();
|
||||
})
|
||||
.then(function() {
|
||||
console.log(chalk.green("\u2713 Test passed: deleting functions"));
|
||||
return testCreateUpdateWithFilter();
|
||||
})
|
||||
.then(function() {
|
||||
console.log(chalk.green("\u2713 Test passed: creating functions with filters"));
|
||||
return testDeleteWithFilter();
|
||||
})
|
||||
.then(function() {
|
||||
console.log(chalk.green("\u2713 Test passed: deleting functions with filters"));
|
||||
return testUnknownFilter();
|
||||
})
|
||||
.then(function() {
|
||||
console.log(
|
||||
chalk.green("\u2713 Test passed: threw warning when passing filter with unknown identifier")
|
||||
);
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log(chalk.red("Error while running tests: "), err);
|
||||
return RSVP.resolve();
|
||||
})
|
||||
.then(postTest);
|
||||
};
|
||||
|
||||
main();
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user