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

test: add pi-hole test container integration test #649

Merged
merged 5 commits into from
Jun 10, 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"cross-env": "^7.0.3",
"jsdom": "^24.1.0",
"prettier": "^3.3.1",
"testcontainers": "^10.9.0",
"turbo": "^2.0.3",
"typescript": "^5.4.5",
"vite-tsconfig-paths": "^4.3.2",
Expand Down
51 changes: 51 additions & 0 deletions packages/integrations/test/pi-hole.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { StartedTestContainer } from "testcontainers";
import { GenericContainer, Wait } from "testcontainers";
import { describe, expect, test } from "vitest";

import { PiHoleIntegration } from "../src";

const DEFAULT_PASSWORD = "12341234";
const DEFAULT_API_KEY = "3b1434980677dcf53fa8c4a611db3b1f0f88478790097515c0abb539102778b9"; // Some hash generated from password

describe("Pi-hole integration", () => {
test("getSummaryAsync should return summary from pi-hole", async () => {
// Arrange
const piholeContainer = await createPiHoleContainer(DEFAULT_PASSWORD).start();
const piHoleIntegration = createPiHoleIntegration(piholeContainer, DEFAULT_API_KEY);

// Act
const result = await piHoleIntegration.getSummaryAsync();

// Assert
expect(result.adsBlockedToday).toBe(0);
manuel-rw marked this conversation as resolved.
Show resolved Hide resolved
expect(result.adsBlockedTodayPercentage).toBe(0);
expect(result.dnsQueriesToday).toBe(0);
expect(result.domainsBeingBlocked).toBeGreaterThan(1);

// Cleanup
await piholeContainer.stop();
}, 20_000); // Timeout of 20 seconds
});

const createPiHoleContainer = (password: string) => {
return new GenericContainer("pihole/pihole:latest")
.withEnvironment({
WEBPASSWORD: password,
})
.withExposedPorts(80)
.withWaitStrategy(Wait.forLogMessage("Pi-hole Enabled"));
};

const createPiHoleIntegration = (container: StartedTestContainer, apiKey: string) => {
return new PiHoleIntegration({
id: "1",
decryptedSecrets: [
{
kind: "apiKey",
value: apiKey,
},
],
name: "Pi hole",
url: `http://${container.getHost()}:${container.getMappedPort(80)}`,
});
};
2 changes: 1 addition & 1 deletion packages/integrations/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},
"include": ["*.ts", "src"],
"include": ["*.ts", "src", "test"],
"exclude": ["node_modules"]
}
Loading
Loading