-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debug: trial folder-level separation (DONOTMERGE) #4060
base: main
Are you sure you want to change the base?
Changes from 6 commits
d0986e0
2e6d896
e7b7e5b
ad5d5d2
9880ddf
5593548
3783a33
5600ffb
15c69c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "nodejs-docs-samples-compute-custom-hostname-instance", | ||
"license": "Apache-2.0", | ||
"author": "Google Inc.", | ||
"engines": { | ||
"node": ">=16.0.0" | ||
}, | ||
"repository": "googleapis/nodejs-compute", | ||
"private": true, | ||
"files": [ | ||
"*.js" | ||
], | ||
"scripts": { | ||
"test": "c8 mocha -p -j 2 test --timeout 300000" | ||
}, | ||
"dependencies": { | ||
"@google-cloud/compute": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"c8": "^10.0.0", | ||
"chai": "^4.5.0", | ||
"mocha": "^10.0.0", | ||
"uuid": "^10.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// 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. | ||
|
||
'use strict'; | ||
|
||
const compute = require('@google-cloud/compute'); | ||
|
||
const {describe, it} = require('mocha'); | ||
const uuid = require('uuid'); | ||
const cp = require('child_process'); | ||
const {assert} = require('chai'); | ||
|
||
const instancesClient = new compute.InstancesClient(); | ||
|
||
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); | ||
|
||
const getInstance = async (projectId, zone, instanceName) => { | ||
const [instance] = await instancesClient.get({ | ||
project: projectId, | ||
zone, | ||
instance: instanceName, | ||
}); | ||
return instance; | ||
}; | ||
|
||
|
||
// DEBUG: copied from createInstance.js, could be simplified. | ||
const createInstance = async (projectId, zone, instanceName) => { | ||
|
||
const machineType = 'n1-standard-1'; | ||
const sourceImage = 'projects/debian-cloud/global/images/family/debian-11'; | ||
const networkName = 'global/networks/default'; | ||
console.log(`Creating the ${instanceName} instance in ${zone}...`); | ||
|
||
const [response] = await instancesClient.insert({ | ||
instanceResource: { | ||
name: instanceName, | ||
disks: [ | ||
{ | ||
initializeParams: { | ||
diskSizeGb: '10', | ||
sourceImage, | ||
}, | ||
autoDelete: true, | ||
boot: true, | ||
type: 'PERSISTENT', | ||
}, | ||
], | ||
machineType: `zones/${zone}/machineTypes/${machineType}`, | ||
networkInterfaces: [ | ||
{ | ||
name: networkName, | ||
}, | ||
], | ||
}, | ||
project: projectId, | ||
zone, | ||
}); | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This // Consider importing createInstance from a shared utility module
// import { createInstance } from '../utils';
// Or define it in a shared location
const createInstance = async (projectId, zone, instanceName) => {
const machineType = 'n1-standard-1';
const sourceImage = 'projects/debian-cloud/global/images/family/debian-11';
const networkName = 'global/networks/default';
console.log(`Creating the ${instanceName} instance in ${zone}...`);
const [response] = await instancesClient.insert({
instanceResource: {
name: instanceName,
disks: [
{
initializeParams: {
diskSizeGb: '10',
sourceImage,
},
autoDelete: true,
boot: true,
type: 'PERSISTENT',
},
],
machineType: `zones/${zone}/machineTypes/${machineType}`,
networkInterfaces: [
{
name: networkName,
},
],
},
project: projectId,
zone,
});
} |
||
|
||
describe('Instance with a custom hostname samples', () => { | ||
const zone = 'europe-central2-b'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const custom_hostname = 'host.domain.com'; | ||
|
||
|
||
|
||
it('should create instance with a custom hostname and return correct hostname', async () => { | ||
const instanceName = `gcloud-test-instance-${uuid.v4().split('-')[0]}`; | ||
const projectId = await instancesClient.getProjectId(); | ||
let output = execSync( | ||
`node createInstanceWithCustomHostname ${projectId} ${zone} ${instanceName} ${custom_hostname}` | ||
); | ||
|
||
const instance = await getInstance(projectId, zone, instanceName); | ||
|
||
assert.equal(instance.hostname, custom_hostname); | ||
assert.match(output, /Instance created./); | ||
|
||
output = execSync( | ||
`node getInstanceHostname ${projectId} ${zone} ${instanceName}` | ||
); | ||
|
||
assert.include( | ||
output, | ||
`Instance ${instanceName} has hostname: ${custom_hostname}` | ||
); | ||
|
||
await instancesClient.delete({ | ||
project: projectId, | ||
zone: zone, | ||
instance: instanceName, | ||
}); | ||
}); | ||
|
||
it('should return undefined if hostname is not set', async () => { | ||
|
||
const instanceName = `gcloud-test-instance-${uuid.v4().split('-')[0]}`; | ||
const projectId = await instancesClient.getProjectId(); | ||
|
||
await createInstance(projectId, zone, instanceName); | ||
console.log("Instance", instanceName, "created") | ||
Check warning on line 113 in compute/custom-hostname-instance/test/customHostnameInstance.test.js
|
||
const output = execSync( | ||
`node getInstanceHostname ${projectId} ${zone} ${instanceName}` | ||
); | ||
|
||
assert.include(output, `Instance ${instanceName} has hostname: undefined`); | ||
|
||
await instancesClient.delete({ | ||
project: projectId, | ||
zone: zone, | ||
instance: instanceName, | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This timeout value seems quite high. Is it necessary? Consider reducing it if possible to speed up the tests.