Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Undermaken committed Jun 17, 2019
1 parent 4dd57d3 commit a1cb99b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
16 changes: 12 additions & 4 deletions src/utils/azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,23 @@ export const getStorageConnection = async (name: string) =>
* hasCosmosConnection checks if the host has az cli installed and resouceGroup and name
* are valid inputs for cosmosdb
*/
export const hasCosmosConnection = (resourceGroup: string, name: string) => {
export const hasCosmosConnection = async (
resourceGroup: string,
name: string
) => {
try {
execa.sync(
const successExitCode = "SUCCESS";
const documentEndpoint = await execa(
`az cosmosdb show -g ${resourceGroup} -n ${name} --query documentEndpoint -o tsv`
);
execa.sync(
const primaryReadonlyMasterKey = execa.sync(
`az cosmosdb list-keys -g ${resourceGroup} -n ${name} --query primaryReadonlyMasterKey -o tsv`
);
return true;

return (
documentEndpoint.exitCodeName === successExitCode &&
primaryReadonlyMasterKey.exitCodeName === successExitCode
);
} catch (e) {
return false;
}
Expand Down
39 changes: 18 additions & 21 deletions test/commands/users/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@ import { expect, test } from "@oclif/test";
import { hasCosmosConnection } from "../../../src/utils/azure";

describe("list all profiles", () => {
const isCosmosConnectionAvailable = hasCosmosConnection(
"agid-rg-test",
"agid-cosmosdb-test"
);
/**
* if host has the az client installed and valid cosmos credentials we test command first output line matches
* the header row (fiscalCode column name). Otherwise the test expects for an error with 2 as exit status
* the header row (fiscalCode column name). Otherwise the test will be skipped
*/
if (isCosmosConnectionAvailable) {
test
.stdout()
.command(["profiles:list"])
.it("runs profiles command to list all users", ctx => {
expect(ctx.stdout).match(/^fiscalCode/);
});
} else {
test
.stdout()
.command(["profiles:list"])
.exit(2)
.it(
"check the command goes in error (no cosmos credential available or az client not installed)"
);
}

before(async function(): Promise<void> {
const isCosmosConnectionAvailable = await hasCosmosConnection(
"agid-rg-test",
"agid-cosmosdb-test"
);
if (!isCosmosConnectionAvailable) {
// tslint:disable-next-line: no-invalid-this
this.skip();
}
});
test
.stdout()
.command(["profiles:list"])
.it("runs profiles command to list all users", ctx => {
expect(ctx.stdout).match(/^fiscalCode/);
});
});

0 comments on commit a1cb99b

Please sign in to comment.