Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: test resource graph command #10

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { HumctlAdapter } from './adapters/humctl/HumctlAdapter';
import { LoginController } from './controllers/LoginController';
import { LoginService } from './services/LoginService';

const loggerChannel = vscode.window.createOutputChannel('Humanitec');
export const loggerChannel = vscode.window.createOutputChannel('Humanitec');

export async function activate(context: vscode.ExtensionContext) {
const logger = new LoggerService(loggerChannel);
Expand Down
105 changes: 105 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import waitForExpect from 'wait-for-expect';
import { HumanitecSidebarController } from '../../controllers/HumanitecSidebarController';
import { ConfigurationRepository } from '../../repos/ConfigurationRepository';
import { ConfigKey } from '../../domain/ConfigKey';
import { Environment } from '../../domain/Environment';
import { loggerChannel } from '../../extension';

const wait = (ms: number) =>
new Promise<void>(resolve => setTimeout(() => resolve(), ms));
Expand All @@ -31,6 +33,8 @@ suite('Extension Test Suite', () => {
let sandbox: sinon.SinonSandbox;
let showErrorMessage: sinon.SinonSpy;

const outputs: string[] = [];

beforeEach(async () => {
sandbox = sinon.createSandbox();
showErrorMessage = sandbox
Expand All @@ -42,6 +46,11 @@ suite('Extension Test Suite', () => {
}
);

sandbox.stub(loggerChannel, 'appendLine').callsFake((value: string) => {
console.log('output', value);
outputs.push(value);
});

humanitecOrg = readEnv('TEST_HUMANITEC_ORG');
humanitecToken = readEnv('TEST_HUMANITEC_TOKEN');

Expand Down Expand Up @@ -157,4 +166,100 @@ suite('Extension Test Suite', () => {
500
);
});

suite('resource graph', () => {
test('fails without app / env', async () => {
await vscode.commands.executeCommand(
'humanitec.sidebar.organization_structure.set_in_workspace',
new Organization(humanitecOrg, 'test-org')
);

await vscode.commands.executeCommand('humanitec.display_resources_graph');

await waitForExpect(
() => {
expect(showErrorMessage).to.have.been.called;
},
10000,
500
);

expect(showErrorMessage).to.have.been.calledWith(
'There is no enough context to process the request. Required context is: Application'
);
});

// TODO: We might want to improve this case.
test('fails with a not existing app / env', async () => {
await vscode.commands.executeCommand(
'humanitec.sidebar.organization_structure.set_in_workspace',
new Environment(
'development',
'Development',
humanitecOrg,
'not-found-app'
)
);

await vscode.commands.executeCommand('humanitec.display_resources_graph');

await waitForExpect(
() => {
expect(showErrorMessage).to.have.been.called;
},
10000,
500
);

expect(showErrorMessage).to.have.been.calledWith(
'Unexpected error occurred. Please contact the extension developer'
);
});

// TODO: We might want to improve this case.
test('fails with a not deployed app / env', async () => {
await vscode.commands.executeCommand(
'humanitec.sidebar.organization_structure.set_in_workspace',
new Environment(
'development',
'Development',
humanitecOrg,
'not-deployed'
)
);

await vscode.commands.executeCommand('humanitec.display_resources_graph');

await waitForExpect(
() => {
expect(showErrorMessage).to.have.been.called;
},
10000,
500
);

expect(showErrorMessage).to.have.been.calledWith(
'Environment development has no deployments. Deploy application to development environment first.'
);
});

test('works with a deployed app / env', async () => {
await vscode.commands.executeCommand(
'humanitec.sidebar.organization_structure.set_in_workspace',
new Environment('development', 'Development', humanitecOrg, 'deployed')
);

await vscode.commands.executeCommand('humanitec.display_resources_graph');

await waitForExpect(
() => {
expect(
vscode.window.tabGroups.activeTabGroup.activeTab?.label
).to.equal('Resources Graph');
},
10000,
500
);
});
});
});
Loading