|
| 1 | +/* |
| 2 | + * Copyright 2024 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +'use strict'; |
| 17 | +const path = require('path'); |
| 18 | +const {before, describe, it} = require('mocha'); |
| 19 | +const {expect} = require('chai'); |
| 20 | +const cp = require('child_process'); |
| 21 | +const {ReservationsClient} = require('@google-cloud/compute').v1; |
| 22 | +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); |
| 23 | +const cwd = path.join(__dirname, '..'); |
| 24 | + |
| 25 | +describe('Delete compute reservation', async () => { |
| 26 | + const reservationName = 'reservation-01'; |
| 27 | + const zone = 'us-central1-a'; |
| 28 | + const reservationsClient = new ReservationsClient(); |
| 29 | + let projectId; |
| 30 | + |
| 31 | + before(async () => { |
| 32 | + projectId = await reservationsClient.getProjectId(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should delete reservation', async () => { |
| 36 | + // Create reservation |
| 37 | + execSync('node ./reservations/createReservationFromProperties.js', { |
| 38 | + cwd, |
| 39 | + }); |
| 40 | + |
| 41 | + // Delete created reservation |
| 42 | + execSync('node ./reservations/deleteReservation.js', { |
| 43 | + cwd, |
| 44 | + }); |
| 45 | + |
| 46 | + try { |
| 47 | + // Try to get the deleted reservation |
| 48 | + await reservationsClient.get({ |
| 49 | + project: projectId, |
| 50 | + zone, |
| 51 | + reservation: reservationName, |
| 52 | + }); |
| 53 | + |
| 54 | + // If the reservation is found, the test should fail |
| 55 | + throw new Error('Reservation was not deleted.'); |
| 56 | + } catch (error) { |
| 57 | + // Assert that the error message indicates the reservation wasn't found |
| 58 | + expect(error.message).to.include( |
| 59 | + `The resource 'projects/${projectId}/zones/${zone}/reservations/reservation-01' was not found` |
| 60 | + ); |
| 61 | + } |
| 62 | + }); |
| 63 | +}); |
0 commit comments