|
| 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 | +// 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 | +import { execSync } from 'node:child_process'; |
| 16 | +import { dirname, resolve } from 'node:path' |
| 17 | +import { fileURLToPath } from 'node:url' |
| 18 | +import t from 'tap'; |
| 19 | + |
| 20 | +function generatePrismaClient() { |
| 21 | + const p = fileURLToPath(import.meta.url) |
| 22 | + const __dirname = dirname(p) |
| 23 | + const schemaPath = resolve(__dirname, '../schema.prisma'); |
| 24 | + |
| 25 | + execSync(`npx prisma generate --schema=${schemaPath}`); |
| 26 | +} |
| 27 | + |
| 28 | +t.test('mysql prisma mjs', async t => { |
| 29 | + // prisma client generation should normally be part of a regular Prisma |
| 30 | + // setup on user end but in order to tests in many different databases |
| 31 | + // we run the generation step at runtime for each variation |
| 32 | + generatePrismaClient(); |
| 33 | + |
| 34 | + const { connect } = await import('../connect.mjs'); |
| 35 | + const { prisma, close } = await connect({ |
| 36 | + instanceConnectionName: process.env.MYSQL_IAM_CONNECTION_NAME, |
| 37 | + user: process.env.MYSQL_IAM_USER, |
| 38 | + database: process.env.MYSQL_DB, |
| 39 | + }); |
| 40 | + const [{ now }] = await prisma.$queryRaw`SELECT NOW() as now` |
| 41 | + t.ok(now.getTime(), 'should have valid returned date object'); |
| 42 | + await close(); |
| 43 | +}); |
0 commit comments