diff --git a/.github/config/nodejs-dev.jsonc b/.github/config/nodejs-dev.jsonc index b2192a0525..6970754883 100644 --- a/.github/config/nodejs-dev.jsonc +++ b/.github/config/nodejs-dev.jsonc @@ -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", diff --git a/.github/config/nodejs-prod.jsonc b/.github/config/nodejs-prod.jsonc index da7625698a..6b06b2956d 100644 --- a/.github/config/nodejs-prod.jsonc +++ b/.github/config/nodejs-prod.jsonc @@ -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 diff --git a/.github/workflows/compute.yaml b/.github/workflows/compute.yaml deleted file mode 100644 index ceb504fe8e..0000000000 --- a/.github/workflows/compute.yaml +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2023 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. - -name: compute -on: - push: - branches: - - main - paths: - - 'compute/**' - - '.github/workflows/compute.yaml' - - '.github/workflows/test.yaml' - pull_request: - types: - - opened - - reopened - - synchronize - - labeled - paths: - - 'compute/**' - - '.github/workflows/compute.yaml' - - '.github/workflows/test.yaml' - schedule: - - cron: '0 0 * * 0' -jobs: - test: - permissions: - contents: 'read' - id-token: 'write' - if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' - uses: ./.github/workflows/test.yaml - with: - name: 'compute' - path: 'compute' - flakybot: - permissions: - contents: 'read' - id-token: 'write' - if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail - uses: ./.github/workflows/flakybot.yaml - needs: [test] diff --git a/compute/custom-hostname-instance/package.json b/compute/custom-hostname-instance/package.json new file mode 100644 index 0000000000..515a13313c --- /dev/null +++ b/compute/custom-hostname-instance/package.json @@ -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" + } +} diff --git a/compute/custom-hostname-instance/test/customHostnameInstance.test.js b/compute/custom-hostname-instance/test/customHostnameInstance.test.js new file mode 100644 index 0000000000..0c77fee332 --- /dev/null +++ b/compute/custom-hostname-instance/test/customHostnameInstance.test.js @@ -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'; + 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, + }); + }); +});