Properly expose errors in ads and tests (#8692)

* add code to expose errors outside zone

* remove unexpect error hiding

* remove uncessary code

* fix tests

* trying to catch more errros

* revert for testing

* wip

* wip

* figured out what was going on

* wip

* fix tests

* fix tests
This commit is contained in:
Anthony Dresser
2019-12-17 12:06:36 -08:00
committed by GitHub
parent 6b5c31410d
commit ea5f9be441
29 changed files with 483 additions and 790 deletions

View File

@@ -105,12 +105,7 @@ export class AccountManagementService implements IAccountManagementService {
}
return Promise.resolve();
});
}).then(
() => { },
reason => {
console.warn(`Account update handler encountered error: ${reason}`);
}
);
});
}

View File

@@ -56,7 +56,7 @@ suite('Account Management Service Tests:', () => {
assert.ok(ams.updateAccountListEvent);
});
test('Account Updated - account added', done => {
test('Account Updated - account added', async () => {
// Setup:
// ... Create account management service and to mock up the store
let state = getTestState();
@@ -79,19 +79,16 @@ suite('Account Management Service Tests:', () => {
};
// If: I update an account that doesn't exist
state.accountManagementService.accountUpdated(account)
.then(() => {
// Then: Make sure the mocked methods are called
state.mockAccountStore.verify(x => x.addOrUpdate(TypeMoq.It.isAny()), TypeMoq.Times.once());
state.mockAccountStore.verify(x => x.remove(TypeMoq.It.isAny()), TypeMoq.Times.once());
})
.then(
() => done(),
err => done(err)
);
try {
await state.accountManagementService.accountUpdated(account);
assert.fail('Should have failed with new account being added');
} catch (e) {
state.mockAccountStore.verify(x => x.addOrUpdate(TypeMoq.It.isAny()), TypeMoq.Times.once());
state.mockAccountStore.verify(x => x.remove(TypeMoq.It.isAny()), TypeMoq.Times.once());
}
});
test('Account Updated - account modified', done => {
test('Account Updated - account modified', () => {
// Setup:
// ... Create account management service and to mock up the store
let state = getTestState();
@@ -111,7 +108,7 @@ suite('Account Management Service Tests:', () => {
metadata: hasAccountProvider
};
// If: I update an account that exists
state.accountManagementService.accountUpdated(account)
return state.accountManagementService.accountUpdated(account)
.then(() => {
// Then:
// ... The mocked method was called
@@ -123,14 +120,10 @@ suite('Account Management Service Tests:', () => {
assert.ok(Array.isArray(params.accountList));
assert.equal(params.accountList.length, 1);
});
})
.then(
() => done(),
err => done(err)
);
});
});
test('Add account - provider exists, account does not exist', done => {
test('Add account - provider exists, account does not exist', () => {
// Setup:
// ... Create account management service with a provider
let state = getTestState();
@@ -166,14 +159,10 @@ suite('Account Management Service Tests:', () => {
assert.equal(param.accountList.length, 1);
assert.equal(param.accountList[0], account);
});
})
.then(
() => done(),
err => done(err)
);
});
});
test('Add account - provider exists, account exists', done => {
test('Add account - provider exists, account exists', () => {
// Setup:
// ... Create account management service with a provider
let state = getTestState();
@@ -209,28 +198,22 @@ suite('Account Management Service Tests:', () => {
assert.equal(param.accountList.length, 1);
assert.equal(param.accountList[0], account);
});
})
.then(
() => done(),
err => done(err)
);
});
});
test('Add account - provider doesn\'t exist', done => {
test('Add account - provider doesn\'t exist', () => {
// Setup: Create account management service
let ams = getTestState().accountManagementService;
// If: I add an account when the provider doesn't exist
// Then: It should not resolve
Promise.race([
return Promise.race([
new Promise((resolve, reject) => setTimeout(() => resolve(), 100)),
ams.addAccount('doesNotExist').then((
() => done('Promise resolved when the provider did not exist')
))
]).then(() => done(), err => done(err));
ams.addAccount('doesNotExist').then(() => { throw new Error('Promise resolved when the provider did not exist'); })
]);
});
test('Add account - provider exists, provider fails', done => {
test('Add account - provider exists, provider fails', async () => {
// Setup: Create account management service with a provider
let state = getTestState();
let mockProvider = getFailingMockAccountProvider(false);
@@ -238,14 +221,13 @@ suite('Account Management Service Tests:', () => {
// If: I ask to add an account and the user cancels
// Then: Nothing should have happened and the promise should be resolved
return state.accountManagementService.addAccount(noAccountProvider.id)
.then(
() => done('Add account promise resolved when it should have rejected'),
() => done()
);
try {
await state.accountManagementService.addAccount(noAccountProvider.id);
assert.fail('Add account promise resolved when it should have rejected');
} catch (e) { }
});
test('Add account - provider exists, user cancelled', done => {
test('Add account - provider exists, user cancelled', () => {
// Setup: Create account management service with a provider
let state = getTestState();
let mockProvider = getFailingMockAccountProvider(true);
@@ -253,14 +235,10 @@ suite('Account Management Service Tests:', () => {
// If: I ask to add an account and the user cancels
// Then: Nothing should have happened and the promise should be resolved
return state.accountManagementService.addAccount(noAccountProvider.id)
.then(
() => done(),
err => done(err)
);
return state.accountManagementService.addAccount(noAccountProvider.id);
});
test('Get account provider metadata - providers exist', done => {
test('Get account provider metadata - providers exist', () => {
// Setup: Create account management service with a provider
let state = getTestState();
state.accountManagementService._providers[noAccountProvider.id] = {
@@ -276,45 +254,35 @@ suite('Account Management Service Tests:', () => {
assert.ok(Array.isArray(result));
assert.equal(result.length, 1);
assert.equal(result[0], noAccountProvider);
})
.then(
() => done(),
err => done(err)
);
});
});
test('Get account provider metadata - no providers', done => {
test('Get account provider metadata - no providers', () => {
// Setup: Create account management service
let ams = getTestState().accountManagementService;
// If: I ask for account provider metadata when there isn't any providers
ams.getAccountProviderMetadata()
return ams.getAccountProviderMetadata()
.then(result => {
// Then: The results should be an empty array
assert.ok(Array.isArray(result));
assert.equal(result.length, 0);
})
.then(
() => done(),
err => done(err)
);
});
});
test('Get accounts by provider - provider does not exist', done => {
test('Get accounts by provider - provider does not exist', () => {
// Setup: Create account management service
let ams = getTestState().accountManagementService;
// If: I get accounts when the provider doesn't exist
// Then: It should not resolve
Promise.race([
return Promise.race([
new Promise((resolve, reject) => setTimeout(() => resolve(), 100)),
ams.getAccountsForProvider('doesNotExist').then((
() => done('Promise resolved when the provider did not exist')
))
]).then(() => done(), err => done(err));
ams.getAccountsForProvider('doesNotExist').then(() => { throw new Error('Promise resolved when the provider did not exist'); })
]);
});
test('Get accounts by provider - provider exists, no accounts', done => {
test('Get accounts by provider - provider exists, no accounts', () => {
// Setup: Create account management service
let ams = getTestState().accountManagementService;
ams._providers[noAccountProvider.id] = {
@@ -324,19 +292,15 @@ suite('Account Management Service Tests:', () => {
};
// If: I ask for the accounts for a provider with no accounts
ams.getAccountsForProvider(noAccountProvider.id)
return ams.getAccountsForProvider(noAccountProvider.id)
.then(result => {
// Then: I should get back an empty array
assert.ok(Array.isArray(result));
assert.equal(result.length, 0);
})
.then(
() => done(),
err => done(err)
);
});
});
test('Get accounts by provider - provider exists, has accounts', done => {
test('Get accounts by provider - provider exists, has accounts', () => {
// Setup: Create account management service
let ams = getTestState().accountManagementService;
ams._providers[hasAccountProvider.id] = {
@@ -346,18 +310,14 @@ suite('Account Management Service Tests:', () => {
};
// If: I ask for the accounts for a provider with accounts
ams.getAccountsForProvider(hasAccountProvider.id)
return ams.getAccountsForProvider(hasAccountProvider.id)
.then(result => {
// Then: I should get back the list of accounts
assert.equal(result, accountList);
})
.then(
() => done(),
err => done(err)
);
});
});
test('Remove account - account exists', done => {
test('Remove account - account exists', () => {
// Setup:
// ... Create account management service and to fake removing an account that exists
let state = getTestState();
@@ -374,7 +334,7 @@ suite('Account Management Service Tests:', () => {
};
// If: I remove an account that exists
state.accountManagementService.removeAccount(account.key)
return state.accountManagementService.removeAccount(account.key)
.then(result => {
// Then:
// ... I should have gotten true back
@@ -392,14 +352,10 @@ suite('Account Management Service Tests:', () => {
assert.ok(Array.isArray(params.accountList));
assert.equal(params.accountList.length, 0);
});
})
.then(
() => done(),
err => done(err)
);
});
});
test('Remove account - account doesn\'t exist', done => {
test('Remove account - account doesn\'t exist', () => {
// Setup:
// ... Create account management service and to fake removing an account that doesn't exist
let state = getTestState();
@@ -417,7 +373,7 @@ suite('Account Management Service Tests:', () => {
// If: I remove an account that doesn't exist
let accountKey = { providerId: noAccountProvider.id, accountId: 'foobar' };
state.accountManagementService.removeAccount(accountKey)
return state.accountManagementService.removeAccount(accountKey)
.then(result => {
// Then:
// ... I should have gotten false back
@@ -431,14 +387,10 @@ suite('Account Management Service Tests:', () => {
// ... The updated account list event should not have fired
state.eventVerifierUpdate.assertNotFired();
})
.then(
() => done(),
err => done(err)
);
});
});
test('Open account dialog - first call', done => {
test('Open account dialog - first call', () => {
// Setup:
// ... Create account management ervice
let state = getTestState();
@@ -450,7 +402,7 @@ suite('Account Management Service Tests:', () => {
.returns(() => mockDialogController.object);
// If: I open the account dialog when it doesn't exist
state.accountManagementService.openAccountListDialog()
return state.accountManagementService.openAccountListDialog()
.then(() => {
// Then:
// ... The instantiation service should have been called once
@@ -458,14 +410,10 @@ suite('Account Management Service Tests:', () => {
// ... The dialog should have been opened
mockDialogController.verify(x => x.openAccountDialog(), TypeMoq.Times.once());
})
.then(
() => done(),
err => done(err)
);
});
});
test('Open account dialog - subsequent calls', done => {
test('Open account dialog - subsequent calls', () => {
// Setup:
// ... Create account management ervice
let state = getTestState();
@@ -477,7 +425,7 @@ suite('Account Management Service Tests:', () => {
.returns(() => mockDialogController.object);
// If: I open the account dialog for a second time
state.accountManagementService.openAccountListDialog()
return state.accountManagementService.openAccountListDialog()
.then(() => state.accountManagementService.openAccountListDialog())
.then(() => {
// Then:
@@ -486,18 +434,14 @@ suite('Account Management Service Tests:', () => {
// ... The dialog should have been opened twice
mockDialogController.verify(x => x.openAccountDialog(), TypeMoq.Times.exactly(2));
})
.then(
() => done(),
err => done(err)
);
});
});
// test('Perform oauth - success', done => {
// TODO: implement this test properly once we remove direct IPC calls (see https://github.com/Microsoft/carbon/issues/2091)
// });
test('Register provider - success', done => {
test('Register provider - success', () => {
// Setup:
// ... Create ams, account store that will accept account add/update
let mocks = getTestState();
@@ -508,7 +452,7 @@ suite('Account Management Service Tests:', () => {
let mockProvider = getMockAccountProvider();
// If: I register a new provider
mocks.accountManagementService.registerProvider(noAccountProvider, mockProvider.object)
return mocks.accountManagementService.registerProvider(noAccountProvider, mockProvider.object)
.then(() => {
// Then:
// ... Account store should have been called to get dehydrated accounts
@@ -523,29 +467,24 @@ suite('Account Management Service Tests:', () => {
assert.ok(Array.isArray(param.initialAccounts));
assert.equal(param.initialAccounts.length, 0);
});
})
.then(
() => done(),
err => done(err)
);
});
});
test('Unregister provider - success', done => {
test('Unregister provider - success', () => {
// Setup:
// ... Create ams
let mocks = getTestState();
// ... Register a provider to remove
let mockProvider = getMockAccountProvider();
mocks.accountManagementService.registerProvider(noAccountProvider, mockProvider.object)
return mocks.accountManagementService.registerProvider(noAccountProvider, mockProvider.object)
.then((success) => {
// If: I remove an account provider
mocks.accountManagementService.unregisterProvider(noAccountProvider);
// Then: The provider removed event should have fired
mocks.eventVerifierProviderRemoved.assertFired(noAccountProvider);
}, error => {
}).then(() => done(), err => done(err));
});
});
});

View File

@@ -193,7 +193,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
// Connection Provider Registration
public registerProvider(providerId: string, provider: azdata.ConnectionProvider): void {
if (!this._providers.has(providerId)) {
console.error('Provider', providerId, 'attempted to register but has no metadata');
this._logService.warn('Provider', providerId, 'attempted to register but has no metadata');
let providerType = {
onReady: new Deferred<azdata.ConnectionProvider>(),
properties: undefined

View File

@@ -75,15 +75,11 @@ suite('ConnectionDialogService tests', () => {
});
}
test('handleDefaultOnConnect uses params URI for editor connections', done => {
testHandleDefaultOnConnectUri(true).then(() => done(), err => {
done(err);
});
test('handleDefaultOnConnect uses params URI for editor connections', () => {
return testHandleDefaultOnConnectUri(true);
});
test('handleDefaultOnConnect uses undefined URI for non-editor connections', done => {
testHandleDefaultOnConnectUri(false).then(() => done(), err => {
done(err);
});
test('handleDefaultOnConnect uses undefined URI for non-editor connections', () => {
return testHandleDefaultOnConnectUri(false);
});
});

View File

@@ -242,16 +242,13 @@ suite('SQL ConnectionManagementService tests', () => {
}
}
test('showConnectionDialog should open the dialog with default type given no parameters', done => {
connectionManagementService.showConnectionDialog().then(() => {
test('showConnectionDialog should open the dialog with default type given no parameters', () => {
return connectionManagementService.showConnectionDialog().then(() => {
verifyShowConnectionDialog(undefined, ConnectionType.default, undefined, false);
done();
}).catch(err => {
done(err);
});
});
test('showConnectionDialog should open the dialog with given type given valid input', done => {
test('showConnectionDialog should open the dialog with given type given valid input', () => {
let params: INewConnectionParams = {
connectionType: ConnectionType.editor,
input: {
@@ -264,15 +261,12 @@ suite('SQL ConnectionManagementService tests', () => {
},
runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery
};
connectionManagementService.showConnectionDialog(params).then(() => {
return connectionManagementService.showConnectionDialog(params).then(() => {
verifyShowConnectionDialog(undefined, params.connectionType, params.input.uri, false);
done();
}).catch(err => {
done(err);
});
});
test('showConnectionDialog should pass the model to the dialog if there is a model assigned to the uri', done => {
test('showConnectionDialog should pass the model to the dialog if there is a model assigned to the uri', () => {
let params: INewConnectionParams = {
connectionType: ConnectionType.editor,
input: {
@@ -286,21 +280,18 @@ suite('SQL ConnectionManagementService tests', () => {
runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery
};
connect(params.input.uri).then(() => {
return connect(params.input.uri).then(() => {
let saveConnection = connectionManagementService.getConnectionProfile(params.input.uri);
assert.notEqual(saveConnection, undefined, `profile was not added to the connections`);
assert.equal(saveConnection.serverName, connectionProfile.serverName, `Server names are different`);
connectionManagementService.showConnectionDialog(params).then(() => {
return connectionManagementService.showConnectionDialog(params).then(() => {
verifyShowConnectionDialog(connectionProfile, params.connectionType, params.input.uri, false);
done();
}).catch(err => {
done(err);
});
}, err => done(err));
});
});
test('connect should save profile given options with saveProfile set to true', done => {
test('connect should save profile given options with saveProfile set to true', () => {
let uri: string = 'Editor Uri';
let options: IConnectionCompletionOptions = {
params: undefined,
@@ -310,18 +301,14 @@ suite('SQL ConnectionManagementService tests', () => {
showFirewallRuleOnError: true
};
connect(uri, options).then(() => {
return connect(uri, options).then(() => {
verifyOptions(options);
done();
}).catch(err => {
done(err);
});
});
test('getDefaultProviderId is MSSQL', done => {
test('getDefaultProviderId is MSSQL', () => {
let defaultProvider = connectionManagementService.getDefaultProviderId();
assert.equal(defaultProvider, 'MSSQL', `Default provider is not equal to MSSQL`);
done();
});
/* Andresse 10/5/17 commented this test out since it was only working before my changes by the chance of how Promises work
@@ -343,7 +330,7 @@ suite('SQL ConnectionManagementService tests', () => {
// });
// });
test('connect should pass the params in options to onConnectSuccess callback', done => {
test('connect should pass the params in options to onConnectSuccess callback', () => {
let uri: string = 'Editor Uri';
let paramsInOnConnectSuccess: INewConnectionParams;
let options: IConnectionCompletionOptions = {
@@ -368,41 +355,32 @@ suite('SQL ConnectionManagementService tests', () => {
showFirewallRuleOnError: true
};
connect(uri, options).then(() => {
return connect(uri, options).then(() => {
verifyOptions(options);
assert.notEqual(paramsInOnConnectSuccess, undefined);
assert.equal(paramsInOnConnectSuccess.connectionType, options.params.connectionType);
done();
}).catch(err => {
done(err);
});
});
test('connectAndSaveProfile should show not load the password', done => {
test('connectAndSaveProfile should show not load the password', () => {
let uri: string = 'Editor Uri';
let options: IConnectionCompletionOptions = undefined;
connect(uri, options, true).then(() => {
return connect(uri, options, true).then(() => {
verifyOptions(options, true);
done();
}).catch(err => {
done(err);
});
});
test('connect with undefined uri and options should connect using the default uri', done => {
test('connect with undefined uri and options should connect using the default uri', () => {
let uri = undefined;
let options: IConnectionCompletionOptions = undefined;
connect(uri, options).then(() => {
return connect(uri, options).then(() => {
assert.equal(connectionManagementService.isProfileConnected(connectionProfile), true);
done();
}).catch(err => {
done(err);
});
});
test('failed connection should open the dialog if connection fails', done => {
test('failed connection should open the dialog if connection fails', () => {
let uri = undefined;
let error: string = 'error';
let errorCode: number = 111;
@@ -423,18 +401,15 @@ suite('SQL ConnectionManagementService tests', () => {
callStack: errorCallStack
};
connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
return connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
assert.equal(result.connected, expectedConnection);
assert.equal(result.errorMessage, connectionResult.errorMessage);
verifyShowFirewallRuleDialog(connectionProfile, false);
verifyShowConnectionDialog(connectionProfile, ConnectionType.default, uri, true, connectionResult);
done();
}).catch(err => {
done(err);
});
});
test('failed connection should not open the dialog if the option is set to false even if connection fails', done => {
test('failed connection should not open the dialog if the option is set to false even if connection fails', () => {
let uri = undefined;
let error: string = 'error when options set to false';
let errorCode: number = 111;
@@ -455,18 +430,15 @@ suite('SQL ConnectionManagementService tests', () => {
callStack: errorCallStack
};
connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
return connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
assert.equal(result.connected, expectedConnection);
assert.equal(result.errorMessage, connectionResult.errorMessage);
verifyShowFirewallRuleDialog(connectionProfile, false);
verifyShowConnectionDialog(connectionProfile, ConnectionType.default, uri, true, connectionResult, false);
done();
}).catch(err => {
done(err);
});
});
test('failed firewall rule should open the firewall rule dialog', done => {
test('failed firewall rule should open the firewall rule dialog', () => {
handleFirewallRuleResult.canHandleFirewallRule = true;
resolveHandleFirewallRuleDialog = true;
isFirewallRuleAdded = true;
@@ -484,17 +456,14 @@ suite('SQL ConnectionManagementService tests', () => {
showFirewallRuleOnError: true
};
connect(uri, options, false, connectionProfile, error, errorCode).then(result => {
return connect(uri, options, false, connectionProfile, error, errorCode).then(result => {
assert.equal(result.connected, expectedConnection);
assert.equal(result.errorMessage, expectedError);
verifyShowFirewallRuleDialog(connectionProfile, true);
done();
}).catch(err => {
done(err);
});
});
test('failed firewall rule connection should not open the firewall rule dialog if the option is set to false even if connection fails', done => {
test('failed firewall rule connection should not open the firewall rule dialog if the option is set to false even if connection fails', () => {
handleFirewallRuleResult.canHandleFirewallRule = true;
resolveHandleFirewallRuleDialog = true;
isFirewallRuleAdded = true;
@@ -519,20 +488,17 @@ suite('SQL ConnectionManagementService tests', () => {
callStack: errorCallStack
};
connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
return connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
assert.equal(result.connected, expectedConnection);
assert.equal(result.errorMessage, connectionResult.errorMessage);
verifyShowFirewallRuleDialog(connectionProfile, false);
verifyShowConnectionDialog(connectionProfile, ConnectionType.default, uri, true, connectionResult, false);
done();
}).catch(err => {
done(err);
});
});
test('failed firewall rule connection and failed during open firewall rule should open the firewall rule dialog and connection dialog with error', done => {
test('failed firewall rule connection and failed during open firewall rule should open the firewall rule dialog and connection dialog with error', () => {
handleFirewallRuleResult.canHandleFirewallRule = true;
resolveHandleFirewallRuleDialog = false;
resolveHandleFirewallRuleDialog = true;
isFirewallRuleAdded = true;
let uri = undefined;
@@ -555,18 +521,15 @@ suite('SQL ConnectionManagementService tests', () => {
callStack: errorCallStack
};
connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
return connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
assert.equal(result.connected, expectedConnection);
assert.equal(result.errorMessage, connectionResult.errorMessage);
verifyShowFirewallRuleDialog(connectionProfile, true);
verifyShowConnectionDialog(connectionProfile, ConnectionType.default, uri, true, connectionResult, true);
done();
}).catch(err => {
done(err);
});
});
test('failed firewall rule connection should open the firewall rule dialog. Then canceled firewall rule dialog should not open connection dialog', done => {
test('failed firewall rule connection should open the firewall rule dialog. Then canceled firewall rule dialog should not open connection dialog', () => {
handleFirewallRuleResult.canHandleFirewallRule = true;
resolveHandleFirewallRuleDialog = true;
isFirewallRuleAdded = false;
@@ -591,17 +554,14 @@ suite('SQL ConnectionManagementService tests', () => {
callStack: errorCallStack
};
connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
return connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
assert.equal(result, undefined);
verifyShowFirewallRuleDialog(connectionProfile, true);
verifyShowConnectionDialog(connectionProfile, ConnectionType.default, uri, true, connectionResult, false);
done();
}).catch(err => {
done(err);
});
});
test('connect when password is empty and unsaved should open the dialog', done => {
test('connect when password is empty and unsaved should open the dialog', () => {
let uri = undefined;
let expectedConnection: boolean = false;
let options: IConnectionCompletionOptions = {
@@ -619,18 +579,15 @@ suite('SQL ConnectionManagementService tests', () => {
callStack: undefined
};
connect(uri, options, false, connectionProfileWithEmptyUnsavedPassword).then(result => {
return connect(uri, options, false, connectionProfileWithEmptyUnsavedPassword).then(result => {
assert.equal(result.connected, expectedConnection);
assert.equal(result.errorMessage, connectionResult.errorMessage);
verifyShowConnectionDialog(connectionProfileWithEmptyUnsavedPassword, ConnectionType.default, uri, true, connectionResult);
verifyShowFirewallRuleDialog(connectionProfile, false);
done();
}).catch(err => {
done(err);
});
});
test('connect when password is empty and saved should not open the dialog', done => {
test('connect when password is empty and saved should not open the dialog', () => {
let uri = undefined;
let expectedConnection: boolean = true;
let options: IConnectionCompletionOptions = {
@@ -648,17 +605,14 @@ suite('SQL ConnectionManagementService tests', () => {
callStack: undefined
};
connect(uri, options, false, connectionProfileWithEmptySavedPassword).then(result => {
return connect(uri, options, false, connectionProfileWithEmptySavedPassword).then(result => {
assert.equal(result.connected, expectedConnection);
assert.equal(result.errorMessage, connectionResult.errorMessage);
verifyShowConnectionDialog(connectionProfileWithEmptySavedPassword, ConnectionType.default, uri, true, connectionResult, false);
done();
}).catch(err => {
done(err);
});
});
test('connect from editor when empty password when it is required and saved should not open the dialog', done => {
test('connect from editor when empty password when it is required and saved should not open the dialog', () => {
let uri = 'editor 3';
let expectedConnection: boolean = true;
let options: IConnectionCompletionOptions = {
@@ -688,45 +642,36 @@ suite('SQL ConnectionManagementService tests', () => {
callStack: undefined
};
connect(uri, options, false, connectionProfileWithEmptySavedPassword).then(result => {
return connect(uri, options, false, connectionProfileWithEmptySavedPassword).then(result => {
assert.equal(result.connected, expectedConnection);
assert.equal(result.errorMessage, connectionResult.errorMessage);
verifyShowConnectionDialog(connectionProfileWithEmptySavedPassword, ConnectionType.editor, uri, true, connectionResult, false);
done();
}).catch(err => {
done(err);
});
});
test('doChangeLanguageFlavor should throw on unknown provider', done => {
test('doChangeLanguageFlavor should throw on unknown provider', () => {
// given a provider that will never exist
let invalidProvider = 'notaprovider';
// when I call doChangeLanguageFlavor
// Then I expect it to throw
assert.throws(() => connectionManagementService.doChangeLanguageFlavor('file://my.sql', 'sql', invalidProvider));
done();
});
test('doChangeLanguageFlavor should send event for known provider', done => {
test('doChangeLanguageFlavor should send event for known provider', () => {
// given a provider that is registered
let uri = 'file://my.sql';
let language = 'sql';
let flavor = 'MSSQL';
// when I call doChangeLanguageFlavor
try {
let called = false;
connectionManagementService.onLanguageFlavorChanged((changeParams: azdata.DidChangeLanguageFlavorParams) => {
called = true;
assert.equal(changeParams.uri, uri);
assert.equal(changeParams.language, language);
assert.equal(changeParams.flavor, flavor);
});
connectionManagementService.doChangeLanguageFlavor(uri, language, flavor);
assert.ok(called, 'expected onLanguageFlavorChanged event to be sent');
done();
} catch (error) {
done(error);
}
let called = false;
connectionManagementService.onLanguageFlavorChanged((changeParams: azdata.DidChangeLanguageFlavorParams) => {
called = true;
assert.equal(changeParams.uri, uri);
assert.equal(changeParams.language, language);
assert.equal(changeParams.flavor, flavor);
});
connectionManagementService.doChangeLanguageFlavor(uri, language, flavor);
assert.ok(called, 'expected onLanguageFlavorChanged event to be sent');
});
test('getUniqueConnectionProvidersByNameMap should return non CMS providers', () => {
@@ -744,7 +689,7 @@ suite('SQL ConnectionManagementService tests', () => {
assert.equal(providerNames[1], expectedNames[1]);
});
test('ensureDefaultLanguageFlavor should not send event if uri is connected', done => {
test('ensureDefaultLanguageFlavor should not send event if uri is connected', () => {
let uri: string = 'Editor Uri';
let options: IConnectionCompletionOptions = {
params: undefined,
@@ -758,16 +703,13 @@ suite('SQL ConnectionManagementService tests', () => {
connectionManagementService.onLanguageFlavorChanged((changeParams: azdata.DidChangeLanguageFlavorParams) => {
called = true;
});
connect(uri, options).then(() => {
return connect(uri, options).then(() => {
connectionManagementService.ensureDefaultLanguageFlavor(uri);
assert.equal(called, false, 'do not expect flavor change to be called');
done();
}).catch(err => {
done(err);
});
});
test('getConnectionId returns the URI associated with a connection that has had its database filled in', done => {
test('getConnectionId returns the URI associated with a connection that has had its database filled in', () => {
// Set up the connection management service with a connection corresponding to a default database
let dbName = 'master';
let serverName = 'test_server';
@@ -777,21 +719,16 @@ suite('SQL ConnectionManagementService tests', () => {
let connectionProfileWithDb: IConnectionProfile = assign(connectionProfileWithoutDb, { databaseName: dbName });
// Save the database with a URI that has the database name filled in, to mirror Carbon's behavior
let ownerUri = Utils.generateUri(connectionProfileWithDb);
connect(ownerUri, undefined, false, connectionProfileWithoutDb).then(() => {
try {
// If I get the URI for the connection with or without a database from the connection management service
let actualUriWithDb = connectionManagementService.getConnectionUri(connectionProfileWithDb);
let actualUriWithoutDb = connectionManagementService.getConnectionUri(connectionProfileWithoutDb);
return connect(ownerUri, undefined, false, connectionProfileWithoutDb).then(() => {
// If I get the URI for the connection with or without a database from the connection management service
let actualUriWithDb = connectionManagementService.getConnectionUri(connectionProfileWithDb);
let actualUriWithoutDb = connectionManagementService.getConnectionUri(connectionProfileWithoutDb);
// Then the retrieved URIs should match the one on the connection
let expectedUri = Utils.generateUri(connectionProfileWithoutDb);
assert.equal(actualUriWithDb, expectedUri);
assert.equal(actualUriWithoutDb, expectedUri);
done();
} catch (err) {
done(err);
}
}, err => done(err));
// Then the retrieved URIs should match the one on the connection
let expectedUri = Utils.generateUri(connectionProfileWithoutDb);
assert.equal(actualUriWithDb, expectedUri);
assert.equal(actualUriWithoutDb, expectedUri);
});
});
test('getTabColorForUri returns undefined when there is no connection for the given URI', () => {
@@ -800,7 +737,7 @@ suite('SQL ConnectionManagementService tests', () => {
assert.equal(color, undefined);
});
test('getTabColorForUri returns the group color corresponding to the connection for a URI', done => {
test('getTabColorForUri returns the group color corresponding to the connection for a URI', () => {
// Set up the connection store to give back a group for the expected connection profile
configResult['tabColorMode'] = 'border';
let expectedColor = 'red';
@@ -808,15 +745,10 @@ suite('SQL ConnectionManagementService tests', () => {
color: expectedColor
});
let uri = 'testUri';
connect(uri).then(() => {
try {
let tabColor = connectionManagementService.getTabColorForUri(uri);
assert.equal(tabColor, expectedColor);
done();
} catch (e) {
done(e);
}
}, err => done(err));
return connect(uri).then(() => {
let tabColor = connectionManagementService.getTabColorForUri(uri);
assert.equal(tabColor, expectedColor);
});
});
test('getActiveConnectionCredentials returns the credentials dictionary for a connection profile', () => {

View File

@@ -172,7 +172,7 @@ suite('Insights Utils tests', function () {
equal(resolvedPath, queryFilePath);
});
test('resolveQueryFilePath throws with workspaceRoot var and non-empty workspace not containing file', async (done) => {
test('resolveQueryFilePath throws with workspaceRoot var and non-empty workspace not containing file', async () => {
const tokenizedPath = path.join('${workspaceRoot}', 'test.sql');
// Create mock context service with a folder NOT containing our test file to verify it returns original path
const contextService = new TestContextService(
@@ -204,11 +204,10 @@ suite('Insights Utils tests', function () {
fail('Should have thrown');
}
catch (e) {
done();
}
});
test('resolveQueryFilePath throws with workspaceRoot var and empty workspace', async (done) => {
test('resolveQueryFilePath throws with workspaceRoot var and empty workspace', async () => {
const tokenizedPath = path.join('${workspaceRoot}', 'test.sql');
// Create mock context service with an empty workspace
const contextService = new TestContextService(
@@ -238,7 +237,6 @@ suite('Insights Utils tests', function () {
fail('Should have thrown');
}
catch (e) {
done();
}
});
@@ -298,7 +296,7 @@ suite('Insights Utils tests', function () {
equal(resolvedPath, queryFilePath);
});
test('resolveQueryFilePath throws if invalid param var specified', async (done) => {
test('resolveQueryFilePath throws if invalid param var specified', async () => {
const invalidPath = path.join('${INVALID}', 'test.sql');
const configurationResolverService = new ConfigurationResolverService(
undefined,
@@ -323,7 +321,6 @@ suite('Insights Utils tests', function () {
await instantiationService.invokeFunction(resolveQueryFilePath, invalidPath);
fail('Should have thrown');
} catch (e) {
done();
}
});

View File

@@ -517,7 +517,7 @@ suite('SQL Object Explorer Service tests', () => {
assert.equal(isExpanded, false);
});
test('isExpanded returns false when the parent of the requested node is not expanded', (done) => {
test('isExpanded returns false when the parent of the requested node is not expanded', async () => {
const table1NodePath = objectExplorerExpandInfo.nodes[0].nodePath;
const tableExpandInfo = {
sessionId: sessionId,
@@ -530,26 +530,17 @@ suite('SQL Object Explorer Service tests', () => {
return treeNode.nodePath === table1NodePath;
});
objectExplorerService.registerServerTreeView(serverTreeView.object);
objectExplorerService.createNewSession(mssqlProviderName, connection).then(result => {
objectExplorerService.onSessionCreated(1, objectExplorerSession);
objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, objectExplorerService.getObjectExplorerNode(connection)).then(childNodes => {
sqlOEProvider.setup(x => x.expandNode(TypeMoq.It.isAny())).callback(() => {
objectExplorerService.onNodeExpanded(tableExpandInfo);
}).returns(() => Promise.resolve(true));
objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, find(childNodes, node => node.nodePath === table1NodePath)).then(() => {
// If I check whether the table is expanded, the answer should be yes
const tableNode = find(childNodes, node => node.nodePath === table1NodePath);
tableNode.isExpanded().then(isExpanded => {
try {
assert.equal(isExpanded, false);
done();
} catch (err) {
done(err);
}
}, err => done(err));
}, err => done(err));
}, err => done(err));
}, err => done(err));
await objectExplorerService.createNewSession(mssqlProviderName, connection);
objectExplorerService.onSessionCreated(1, objectExplorerSession);
const childNodes = await objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, objectExplorerService.getObjectExplorerNode(connection));
sqlOEProvider.setup(x => x.expandNode(TypeMoq.It.isAny())).callback(() => {
objectExplorerService.onNodeExpanded(tableExpandInfo);
}).returns(() => Promise.resolve(true));
await objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, find(childNodes, node => node.nodePath === table1NodePath));
// If I check whether the table is expanded, the answer should be yes
const tableNode = find(childNodes, node => node.nodePath === table1NodePath);
const isExpanded = await tableNode.isExpanded();
assert.equal(isExpanded, false);
});
test('setting a node to expanded calls expand on the requested tree node', async () => {