-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add (missing) Node 8 unit tests (#695)
* Add node8 unit tests * Fix lint
- Loading branch information
Ace Nassri
authored
Jul 23, 2018
1 parent
3b9d623
commit 29f1230
Showing
3 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright 2018, Google, Inc. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// [START functions_pubsub_unit_test] | ||
const test = require(`ava`); | ||
const uuid = require(`uuid`); | ||
const sinon = require(`sinon`); | ||
|
||
const helloPubSub = require(`..`).helloPubSub; | ||
const consoleLog = sinon.stub(console, 'log'); | ||
|
||
test(`helloPubSub: should print a name`, async t => { | ||
// Initialize mocks | ||
const name = uuid.v4(); | ||
const event = { | ||
data: Buffer.from(name).toString(`base64`) | ||
}; | ||
|
||
// Call tested function and verify its behavior | ||
await helloPubSub(event); | ||
t.true(consoleLog.calledWith(`Hello, ${name}!`)); | ||
}); | ||
|
||
test(`helloPubSub: should print hello world`, async t => { | ||
// Initialize mocks | ||
const event = {}; | ||
|
||
// Call tested function and verify its behavior | ||
await helloPubSub(event); | ||
t.true(consoleLog.calledWith(`Hello, World!`)); | ||
}); | ||
// [END functions_pubsub_unit_test] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright 2018, Google, Inc. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// [START functions_storage_unit_test] | ||
const test = require(`ava`); | ||
const uuid = require(`uuid`); | ||
const sinon = require(`sinon`); | ||
|
||
const helloGCS = require(`..`).helloGCS; | ||
const consoleLog = sinon.stub(console, 'log'); | ||
|
||
test(`helloGCS: should print uploaded message`, async t => { | ||
// Initialize mocks | ||
const filename = uuid.v4(); | ||
const event = { | ||
name: filename, | ||
resourceState: 'exists', | ||
metageneration: '1' | ||
}; | ||
|
||
// Call tested function and verify its behavior | ||
await helloGCS(event); | ||
t.true(consoleLog.calledWith(`File ${filename} uploaded.`)); | ||
}); | ||
|
||
test(`helloGCS: should print metadata updated message`, async t => { | ||
// Initialize mocks | ||
const filename = uuid.v4(); | ||
const event = { | ||
name: filename, | ||
resourceState: 'exists', | ||
metageneration: '2' | ||
}; | ||
|
||
// Call tested function and verify its behavior | ||
await helloGCS(event); | ||
t.true(consoleLog.calledWith(`File ${filename} metadata updated.`)); | ||
}); | ||
|
||
test(`helloGCS: should print deleted message`, async t => { | ||
// Initialize mocks | ||
const filename = uuid.v4(); | ||
const event = { | ||
name: filename, | ||
resourceState: 'not_exists', | ||
metageneration: '3' | ||
}; | ||
|
||
// Call tested function and verify its behavior | ||
await helloGCS(event); | ||
t.true(consoleLog.calledWith(`File ${filename} deleted.`)); | ||
}); | ||
// [END functions_storage_unit_test] |