Skip to content

Removes config write when removing a connection that doesn't exist #19594

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions src/connectionconfig/connectionconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ export class ConnectionConfig implements IConnectionConfig {
let profiles = await this.getConnections(false /* getWorkspaceConnections */);

const found = this.removeConnectionHelper(profile, profiles);

await this.writeConnectionsToSettings(profiles);
if (found) {
await this.writeConnectionsToSettings(profiles);
}
return found;
}

Expand Down
46 changes: 46 additions & 0 deletions test/unit/connectionConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,52 @@ suite("ConnectionConfig Tests", () => {
);
});

test("removeConnection does not write config if asked to remove a connection that doesn't exist", async () => {
const testConnProfile = {
id: "profile-id",
groupId: rootGroupId,
server: "TestServer",
authenticationType: "Integrated",
profileName: "Test Profile",
} as IConnectionProfile;

// Set up initial connections with a different profile
mockGlobalConfigData.set(Constants.connectionsArrayName, [
{
id: "different-profile-id",
groupId: rootGroupId,
server: "DifferentServer",
authenticationType: "Integrated",
profileName: "Different Profile",
} as IConnectionProfile,
]);

const connConfig = new ConnectionConfig(mockVscodeWrapper.object);
await connConfig.initialized;

// Try to remove a profile that doesn't exist in the config
const result = await connConfig.removeConnection(testConnProfile);

expect(result, "Profile should not have been found").to.be.false;
expect(mockGlobalConfigData.get(Constants.connectionsArrayName)).to.have.lengthOf(
1,
);
expect(mockGlobalConfigData.get(Constants.connectionsArrayName)[0].id).to.equal(
"different-profile-id",
);

// Verify setConfiguration was not called
mockVscodeWrapper.verify(
(v) =>
v.setConfiguration(
TypeMoq.It.isValue(Constants.extensionName),
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
),
TypeMoq.Times.never(),
);
});

test("getConnections filters out workspace connections that are missing IDs", async () => {
const testConnProfiles = [
{
Expand Down
Loading