|
| 1 | +// Copyright 2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +'use strict'; |
| 16 | + |
| 17 | +const {describe, it, beforeEach, afterEach} = require('mocha'); |
| 18 | +const assert = require('assert'); |
| 19 | +const sinon = require('sinon'); |
| 20 | + |
| 21 | +const {setupBeforeAll, cleanupResources} = require('./config'); |
| 22 | +const {viewTableOrViewAccessPolicy} = require('../viewTableOrViewAccessPolicy'); |
| 23 | + |
| 24 | +describe('viewTableOrViewAccessPolicy', () => { |
| 25 | + let datasetId = null; |
| 26 | + let tableId = null; |
| 27 | + const projectId = process.env.GCLOUD_PROJECT; |
| 28 | + |
| 29 | + beforeEach(async () => { |
| 30 | + const response = await setupBeforeAll(); |
| 31 | + datasetId = response.datasetId; |
| 32 | + tableId = response.tableId; |
| 33 | + |
| 34 | + sinon.stub(console, 'log'); |
| 35 | + sinon.stub(console, 'error'); |
| 36 | + }); |
| 37 | + |
| 38 | + afterEach(async () => { |
| 39 | + await cleanupResources(datasetId); |
| 40 | + console.log.restore(); |
| 41 | + console.error.restore(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should view table access policies', async () => { |
| 45 | + // View the table access policy |
| 46 | + await viewTableOrViewAccessPolicy(projectId, datasetId, tableId); |
| 47 | + |
| 48 | + // Check that the right messages were logged |
| 49 | + assert.strictEqual( |
| 50 | + console.log.calledWith( |
| 51 | + `Access Policy details for table or view '${tableId}'.` |
| 52 | + ), |
| 53 | + true |
| 54 | + ); |
| 55 | + |
| 56 | + assert.ok( |
| 57 | + console.log.calledWith(sinon.match('Bindings:')), |
| 58 | + 'Should log bindings information' |
| 59 | + ); |
| 60 | + |
| 61 | + assert.ok( |
| 62 | + console.log.calledWith(sinon.match('etag:')), |
| 63 | + 'Should log etag information' |
| 64 | + ); |
| 65 | + |
| 66 | + assert.ok( |
| 67 | + console.log.calledWith(sinon.match('Version:')), |
| 68 | + 'Should log version information' |
| 69 | + ); |
| 70 | + }); |
| 71 | +}); |
0 commit comments