Skip to content

Commit

Permalink
test: Improve Kitchen Test Logging (#1914)
Browse files Browse the repository at this point in the history
* test: Improve Kitchen Test Logging

- Adds missing STDERR logging for improved debugging, which was missing for a while
- Removes `execa`, as it is unneeded and outdated

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* fix: add 'error' event handle

* test: documentation

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
d-goog and gcf-owl-bot[bot] authored Jan 22, 2025
1 parent 12f2c87 commit f08cd65
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1041,19 +1041,19 @@ class CustomSupplier implements SubjectTokenSupplier {
}

const clientOptions = {
audience: '//iam.googleapis.com/locations/global/workforcePools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID', // Set the GCP audience.
audience: '//iam.googleapis.com/locations/global/workforcePools/$WORKFORCE_POOL_ID/providers/$PROVIDER_ID', // Set the GCP audience.
subject_token_type: 'urn:ietf:params:oauth:token-type:id_token', // Set the subject token type.
subject_token_supplier: new CustomSupplier() // Set the custom supplier.
}

const client = new CustomSupplier(clientOptions);
```

Where the audience is: `//iam.googleapis.com/locations/global/workforcePools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID`
Where the audience is: `//iam.googleapis.com/locations/global/workforcePools/$WORKFORCE_POOL_ID/providers/$PROVIDER_ID`

Where the following variables need to be substituted:

* `WORKFORCE_POOL_ID`: The worforce pool ID.
* `$WORKFORCE_POOL_ID`: The worforce pool ID.
* `$PROVIDER_ID`: The provider ID.

and the workforce pool user project is the project number associated with the [workforce pools user project](https://cloud.google.com/iam/docs/workforce-identity-federation#workforce-pools-user-project).
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"chai": "^4.2.0",
"cheerio": "1.0.0-rc.12",
"codecov": "^3.0.2",
"execa": "^5.0.0",
"gts": "^5.0.0",
"is-docker": "^2.0.0",
"jsdoc": "^4.0.0",
Expand Down
31 changes: 26 additions & 5 deletions system-test/test.kitchen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

import * as assert from 'assert';
import {describe, it, afterEach} from 'mocha';
import * as execa from 'execa';
import * as fs from 'fs';
import * as mv from 'mv';
import {ncp} from 'ncp';
import * as os from 'os';
import * as path from 'path';
import {promisify} from 'util';
import {spawn} from 'child_process';

const mvp = promisify(mv) as {} as (...args: string[]) => Promise<void>;
const ncpp = promisify(ncp);
Expand All @@ -29,18 +29,39 @@ const keep = !!process.env.GALN_KEEP_TEMPDIRS;
const pkg = require('../../package.json');

let stagingDir: string;

/**
* Spawns and runs a command asynchronously.
*
* @param params params to pass to {@link spawn}
*/
async function run(...params: Parameters<typeof spawn>) {
const command = spawn(...params);

await new Promise<void>((resolve, reject) => {
// Unlike `exec`/`execFile`, this keeps the order of STDOUT/STDERR in case they were interweaved;
// making it easier to debug and follow along.
command.stdout?.on('data', console.log);
command.stderr?.on('data', console.error);
command.on('close', (code, signal) => {
return code === 0 ? resolve() : reject({code, signal});
});
command.on('error', reject);
});
}

async function packAndInstall() {
stagingDir = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'google-auth-library-nodejs-pack-')
);

await execa('npm', ['pack'], {stdio: 'inherit'});
await run('npm', ['pack'], {});
const tarball = `${pkg.name}-${pkg.version}.tgz`;
// stagingPath can be on another filesystem so fs.rename() will fail
// with EXDEV, hence we use `mv` module here.
await mvp(tarball, `${stagingDir}/google-auth-library.tgz`);
await ncpp('system-test/fixtures/kitchen', `${stagingDir}/`);
await execa('npm', ['install'], {cwd: `${stagingDir}/`, stdio: 'inherit'});
await run('npm', ['install'], {cwd: `${stagingDir}/`});
}

describe('pack and install', () => {
Expand All @@ -61,10 +82,10 @@ describe('pack and install', () => {
this.timeout(40000);
await packAndInstall();
// we expect npm install is executed in the before hook
await execa('npx', ['webpack'], {cwd: `${stagingDir}/`, stdio: 'inherit'});
await run('npx', ['webpack'], {cwd: `${stagingDir}/`});
const bundle = path.join(stagingDir, 'dist', 'bundle.min.js');
// ensure it is a non-empty bundle
assert(fs.statSync(bundle).size);
assert(fs.statSync(bundle).size, 'Size should not be empty');
});

/**
Expand Down

0 comments on commit f08cd65

Please sign in to comment.