-
Notifications
You must be signed in to change notification settings - Fork 113
docs(samples): update samples to use async/await and mocha #183
Conversation
samples/startup-script/index.js
Outdated
<!doctype html> | ||
<h1>Hello World</h1> | ||
<p>This page was created from a simple start-up script!</p>`, | ||
(async() =>{ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
@@ -26,110 +26,114 @@ const zone = compute.zone('us-central1-a'); | |||
function createVm(name, callback) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
ip | ||
); | ||
|
||
}catch(err){ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
zone | ||
.getVMs() | ||
.then(data => { | ||
(async () => { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
.then(data => { | ||
(async () => { | ||
try{ | ||
const data = await zone.getVMs(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/test/sendgrid.test.js
Outdated
}; | ||
}, | ||
|
||
describe('sendgrid',() =>{ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/quickstart.js
Outdated
.catch(err => { | ||
console.error('ERROR:', err); | ||
}); | ||
const name = 'ubuntu-http1'; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/quickstart.js
Outdated
const vm = data[0]; | ||
const operation = data[1]; | ||
// Virtual machine created! | ||
return operation.promise(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/sendgrid.js
Outdated
} else { | ||
console.log('Mail sent successfully!'); | ||
} | ||
const response = Sendgrid.API(request); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
}; | ||
const vm = zone.vm(name); | ||
console.log('Creating VM ...'); | ||
const data = await vm.create(config); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
console.log('Creating VM ...'); | ||
const data = await vm.create(config); | ||
await data[1].promise(); | ||
const metadata = await vm.getMetadata(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
|
||
const vm = zone.vm(name); | ||
// External IP of the VM. | ||
const ip = metadata[0].networkInterfaces[0].accessConfigs[0].natIP; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
const ip = metadata.networkInterfaces[0].accessConfigs[0].natIP; | ||
console.log(`Booting new VM with IP http://${ip}...`); | ||
// Ping the VM to determine when the HTTP server is ready. | ||
return await pingVM(ip); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
.catch(err => callback(err)); | ||
async function listVms() { | ||
try { | ||
const data = await zone.getVMs(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
await pingVM(ip); | ||
return ip; | ||
} catch (err) { | ||
console.error(`Something went wrong while creating ${name} :`, err); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
try { | ||
const [vms] = await zone.getVMs(); | ||
const results = []; | ||
for (const i in vms) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
name: data[0].name, | ||
}; | ||
}); | ||
} catch (err) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/index.js
Outdated
// VM deleted | ||
return name; | ||
} catch (err) { | ||
console.error(`Something went wrong while deleting ${name} :`, err); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
samples/startup-script/package.json
Outdated
"axios": "^0.18.0" | ||
}, | ||
"engines": { | ||
"node": ">=7.6.0" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@muraliQlogic as soon as the samples tests are passing, would be happy to merge this one :) Let me know if you need any help! |
@JustinBeckwith : Can you please invoke the samples test check. |
samples/startup-script/package.json
Outdated
@@ -4,15 +4,19 @@ | |||
"description": "Start a Google Compute Engine and run the startup script.", | |||
"main": "index.js", | |||
"dependencies": { | |||
"@google-cloud/compute": "0.10.0" | |||
"@google-cloud/compute": "0.10.0", | |||
"axios": "^0.18.0" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@muraliQlogic I sent an invite to the googleapis org on GitHub. If you accept that, it will run the tests for you instead of needing one of us to add a kokoro label :) |
@JustinBeckwith : samples test are passing locally with other project that i am testing with. |
Codecov Report
@@ Coverage Diff @@
## master #183 +/- ##
=========================================
Coverage ? 99.25%
=========================================
Files ? 19
Lines ? 1476
Branches ? 0
=========================================
Hits ? 1465
Misses ? 11
Partials ? 0 Continue to review full report at Codecov.
|
@JustinBeckwith, @muraliQlogic can't add labels for some reason.. |
I just ran |
The samples tests show this:
|
Works towards googleapis/google-cloud-node#2865 and googleapis/google-cloud-node#2869 (it's a good idea to open an issue first for discussion)