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

add deletedns unit test #2057

Merged
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
12 changes: 5 additions & 7 deletions packages/dockerCompose/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ export class ComposeServiceEditor {
}

/**
* Remove the property, dont append undefined to the yaml
* Remove the property directly from the service.
*/
removeDns(): void {
this.edit((service) => {
if (!service.dns) return service;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { dns, ...rest } = service;
return rest;
});
const service = this.get();
if ("dns" in service) {
delete service.dns;
}
}

removeNetworkAliases(networkName: string, aliasesToRemove: string[], serviceNetwork: ComposeServiceNetwork): void {
Expand Down
47 changes: 47 additions & 0 deletions packages/dockerCompose/test/unit/composeDeleteDns.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import "mocha";
import { expect } from "chai";
import { ComposeEditor } from "../../src/index.js";
import { Compose } from "@dappnode/types";

describe("ComposeServiceEditor", function () {
describe("removeDns()", function () {
it("should remove the dns field from the service", function () {
// Create a mock compose object
const mockCompose: Compose = {
version: "3",
services: {
myservice: {
image: "myimage",
dns: "8.8.8.8",
environment: []
}
}
};

// Create a ComposeEditor instance with the mock compose
const composeEditor = new ComposeEditor(mockCompose);

// Get the service editor for 'myservice'
const serviceEditor = composeEditor.services()["myservice"];

// Ensure dns field is present before removal
expect(serviceEditor.get().dns).to.deep.equal("8.8.8.8");

// Call removeDns()
serviceEditor.removeDns();

// Get the updated service
const updatedService = serviceEditor.get();

// Verify that the dns field is removed
expect(updatedService.dns).to.be.undefined;

// Output the compose and check that dns is not present
const outputCompose = composeEditor.output();
expect(outputCompose.services["myservice"].dns).to.be.undefined;

// Ensure other fields remain unchanged
expect(outputCompose.services["myservice"].image).to.equal("myimage");
});
});
});
Loading