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 6 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
1 change: 0 additions & 1 deletion .github/config/nodejs-prod.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"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
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"
}
}
126 changes: 126 additions & 0 deletions compute/custom-hostname-instance/test/customHostnameInstance.test.js
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;
};


Check failure on line 37 in compute/custom-hostname-instance/test/customHostnameInstance.test.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
// DEBUG: copied from createInstance.js, could be simplified.
const createInstance = async (projectId, zone, instanceName) => {

Check failure on line 39 in compute/custom-hostname-instance/test/customHostnameInstance.test.js

View workflow job for this annotation

GitHub Actions / lint

Replace `·=>·{⏎` with `=>·{`

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({

Check failure on line 46 in compute/custom-hostname-instance/test/customHostnameInstance.test.js

View workflow job for this annotation

GitHub Actions / lint

'response' is assigned a value but never used
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,
});

Check failure on line 70 in compute/custom-hostname-instance/test/customHostnameInstance.test.js

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎}` with `};`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This createInstance function is a duplicate of the one found in compute/createInstance.js. Duplicating code makes maintenance harder. Consider importing the function or creating a shared utility function to avoid duplication.

// 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';
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';


Check failure on line 77 in compute/custom-hostname-instance/test/customHostnameInstance.test.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎⏎`

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 () => {

Check failure on line 108 in compute/custom-hostname-instance/test/customHostnameInstance.test.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
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

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

Check warning on line 113 in compute/custom-hostname-instance/test/customHostnameInstance.test.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

Check failure on line 113 in compute/custom-hostname-instance/test/customHostnameInstance.test.js

View workflow job for this annotation

GitHub Actions / lint

Replace `"Instance",·instanceName,·"created")` with `'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