mirror of
https://github.com/github/codeql-action
synced 2026-12-01 13:49:37 +08:00
Add hasEnv delayed assertion and use for getJobUUID test
This commit is contained in:
2 files changed
+27
-10
No files matched your search
@@ -29,21 +29,16 @@ import { BuildMode, ConfigurationError, withTmpDir, wrapError } from "./util";
|
||||
setupTests(test);
|
||||
|
||||
test("getJobUUID - generates valid UUIDs", async (t) => {
|
||||
const exportVariableStub: sinon.SinonStub<[string, string], void> =
|
||||
sinon.stub();
|
||||
|
||||
await callee(getJobUUID)
|
||||
.withArgs()
|
||||
.withActions((env) => {
|
||||
env.exportVariable = exportVariableStub;
|
||||
})
|
||||
.logs(t, "Job run UUID is ")
|
||||
.hasEnv(t, (val) => {
|
||||
return {
|
||||
[EnvVar.JOB_RUN_UUID]: val,
|
||||
};
|
||||
})
|
||||
.passes((val) => {
|
||||
t.true(uuid.validate(val));
|
||||
|
||||
const calls = exportVariableStub.getCalls();
|
||||
t.is(calls.length, 1);
|
||||
t.deepEqual(calls[0].args, [EnvVar.JOB_RUN_UUID, val]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -378,6 +378,28 @@ abstract class BaseEnvBuilder<
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a delayed check that the environment variables returned by `fn`
|
||||
* are present in the environment after the main assertion passes.
|
||||
*/
|
||||
public hasEnv(
|
||||
t: ExecutionContext<unknown>,
|
||||
fn: (
|
||||
value: Awaited<R> | undefined,
|
||||
error: ThrownError<ErrorConstructor | Error> | undefined,
|
||||
) => Record<string, string | undefined>,
|
||||
): this {
|
||||
const result = this.clone();
|
||||
result.checks.push(async (env, r) => {
|
||||
const value = r.orElse(undefined);
|
||||
const error = r.isFailure() ? r.value : undefined;
|
||||
const expected = fn(value, error);
|
||||
|
||||
t.like(env.getState().env.get(), expected);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a delayed check that `messages` are not logged. The check will be
|
||||
* performed after the main assertion passes.
|
||||
|
||||
Reference in new issue
Block a user