Skip to content
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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/config/nodejs-dev.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"functions/pubsub", // parent directory
"memorystore/redis", // parent directory
"recaptcha_enterprise/demosite/app", // no tests exist
"compute", // parent directory

// These tests are already passing in prod, so skip them in dev.
"appengine/building-an-app/build",
Expand Down
2 changes: 1 addition & 1 deletion .github/config/nodejs-prod.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@
"functions/pubsub", // parent directory
"memorystore/redis", // parent directory
"recaptcha_enterprise/demosite/app", // no tests exist
"compute", // parent directory

// TODO: fix these
"ai-platform/snippets", // PERMISSION_DENIED: Permission denied: Consumer 'projects/undefined' has been suspended.
"automl", // (untested) FAILED_PRECONDITION: Google Cloud AutoML Natural Language was retired on March 15, 2024. Please migrate to Vertex AI instead
"cloud-sql/sqlserver/mssql", // (untested) TypeError: The "config.server" property is required and must be of type string.
"cloud-sql/sqlserver/tedious", // (untested) TypeError: The "config.server" property is required and must be of type string.
"compute", // GoogleError: The resource 'projects/long-door-651/zones/us-central1-a/disks/disk-from-pool-name' was not found
"dataproc", // GoogleError: Error submitting create cluster request: Multiple validation errors
"datastore/functions", // [ERR_REQUIRE_ESM]: require() of ES Module
"dialogflow-cx", // NOT_FOUND: com.google.apps.framework.request.NotFoundException: Agent 'undefined' does not exist
Expand Down
52 changes: 0 additions & 52 deletions .github/workflows/compute.yaml

This file was deleted.

25 changes: 25 additions & 0 deletions compute/custom-hostname-instance/package.json
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This timeout value seems quite high. Is it necessary? Consider reducing it if possible to speed up the tests.

"test": "c8 mocha -p -j 2 test --timeout 60000"

},
"dependencies": {
"@google-cloud/compute": "^4.0.0"
},
"devDependencies": {
"c8": "^10.0.0",
"chai": "^4.5.0",
"mocha": "^10.0.0",
"uuid": "^10.0.0"
}
}
120 changes: 120 additions & 0 deletions compute/custom-hostname-instance/test/customHostnameInstance.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// 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}...`);

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The zone is hardcoded here. Consider using a configuration or environment variable to manage the zone for better flexibility and to avoid hardcoding values.

const zone = process.env.GCLOUD_ZONE || 'europe-central2-b';

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');
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,
});
});
});
Loading