|
| 1 | +// Copyright 2024 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 | +// http://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 | +import {Bigtable} from '../src'; |
| 16 | +import * as assert from 'assert'; |
| 17 | +import {describe, it, before, after} from 'mocha'; |
| 18 | + |
| 19 | +describe.only('Bigtable/Table#getRows', () => { |
| 20 | + const bigtable = new Bigtable({ |
| 21 | + projectId: 'cloud-native-db-dpes-shared', |
| 22 | + }); |
| 23 | + const instanceId = 'emulator-test-instance'; |
| 24 | + const tableId = 'my-table'; |
| 25 | + const columnFamilyId = 'cf1'; |
| 26 | + const clusterId = 'test-cluster'; |
| 27 | + const location = 'us-central1-c'; |
| 28 | + |
| 29 | + before(async () => { |
| 30 | + const instance = bigtable.instance(instanceId); |
| 31 | + try { |
| 32 | + const [instanceInfo] = await instance.exists(); |
| 33 | + if (!instanceInfo) { |
| 34 | + const [, operation] = await instance.create({ |
| 35 | + clusters: { |
| 36 | + id: 'fake-cluster3', |
| 37 | + location: 'us-west1-c', |
| 38 | + nodes: 1, |
| 39 | + }, |
| 40 | + }); |
| 41 | + await operation.promise(); |
| 42 | + } |
| 43 | + |
| 44 | + const table = instance.table(tableId); |
| 45 | + const [tableExists] = await table.exists(); |
| 46 | + if (!tableExists) { |
| 47 | + await table.create({families: [columnFamilyId]}); // Create column family |
| 48 | + } else { |
| 49 | + // Check if column family exists and create it if not. |
| 50 | + const [families] = await table.getFamilies(); |
| 51 | + |
| 52 | + if (!families.some(family => family.id === columnFamilyId)) { |
| 53 | + await table.createFamily(columnFamilyId); |
| 54 | + } |
| 55 | + } |
| 56 | + } catch (error) { |
| 57 | + console.error('Error during setup:', error); |
| 58 | + // Consider re-throwing error, to actually stop tests. |
| 59 | + } |
| 60 | + }); |
| 61 | + |
| 62 | + after(async () => { |
| 63 | + const instance = bigtable.instance(instanceId); |
| 64 | + await instance.delete({}); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should read rows after inserting data', async () => { |
| 68 | + const instance = bigtable.instance(instanceId); |
| 69 | + const table = instance.table(tableId); |
| 70 | + const rows = [ |
| 71 | + { |
| 72 | + key: 'row1', |
| 73 | + data: { |
| 74 | + cf1: { |
| 75 | + q1: 'value1', |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + { |
| 80 | + key: 'row2', |
| 81 | + data: { |
| 82 | + cf1: { |
| 83 | + q2: 'value2', |
| 84 | + }, |
| 85 | + }, |
| 86 | + }, |
| 87 | + ]; |
| 88 | + await table.insert(rows); |
| 89 | + for (let i = 0; i < 100; i++) { |
| 90 | + console.log(await table.getRows()); |
| 91 | + } |
| 92 | + }); |
| 93 | +}); |
0 commit comments