-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3f5075
commit 1ff4f69
Showing
4 changed files
with
56 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,36 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
let machineListRequests: (string | Buffer)[] = []; | ||
let machineCountRequests: (string | Buffer)[] = []; | ||
|
||
test.beforeEach(async ({ page, context }) => { | ||
machineListRequests = []; | ||
machineCountRequests = []; | ||
await context.addCookies([ | ||
{ name: "skipsetupintro", value: "true", url: "http://0.0.0.0:5240/" }, | ||
{ name: "skipintro", value: "true", url: "http://0.0.0.0:5240/" }, | ||
]); | ||
await page.goto("/MAAS/r/machines"); | ||
await page.getByLabel("Username").click(); | ||
await page.getByLabel("Username").fill("admin"); | ||
await page.getByLabel("Username").press("Tab"); | ||
await page.getByLabel("Password").fill("test"); | ||
await page.getByLabel("Password").press("Enter"); | ||
}); | ||
import { test } from "@playwright/test"; | ||
import { exec } from "child_process"; | ||
import { promisify } from "util"; | ||
|
||
const execAsync = promisify(exec); | ||
|
||
export async function runMAASCommand( | ||
action: string, | ||
params: string | ||
): Promise<void> { | ||
const apiKey = process.env.MAAS_API_KEY; | ||
const maasURL = process.env.MAAS_URL; | ||
|
||
if (!apiKey || !maasURL) { | ||
throw new Error( | ||
"MAAS_API_KEY or MAAS_URL environment variables are not set." | ||
); | ||
} | ||
|
||
// Login command | ||
const loginCommand = `maas login admin http://${maasURL}/MAAS/api/2.0/ ${apiKey}`; | ||
const actionCommand = `maas admin ${action} ${params}`; | ||
await execAsync(loginCommand); | ||
|
||
const { stdout, stderr } = await execAsync(actionCommand); | ||
|
||
if (stderr) { | ||
throw new Error(`Error executing MAAS command: ${stderr}`); | ||
} | ||
|
||
console.log(stdout); | ||
} | ||
|
||
test("machines list loads", async ({ page }) => { | ||
page.on("websocket", async (ws) => { | ||
console.log(`WebSocket opened: ${ws.url()}>`); | ||
await ws.on("framesent", async (data) => { | ||
console.log(data.payload); | ||
if (data.payload.includes("machine.list")) { | ||
machineListRequests.push(data.payload); | ||
} | ||
if (data.payload.includes("machine.count")) { | ||
machineCountRequests.push(data.payload); | ||
} | ||
}); | ||
ws.on("close", () => console.log("WebSocket closed")); | ||
}); | ||
await expect(page).toHaveTitle(/Machines/); | ||
await expect(page.getByTestId("main-toolbar-heading")).toHaveText( | ||
/[0-9]+ machine[s]? in [0-9]+ pool[s]?/i | ||
); | ||
await expect(page.getByRole("grid", { name: /Loading/i })).toBeHidden(); | ||
// expect a single machine.list and machine.count request | ||
await expect(machineListRequests.length).toBe(1); | ||
await expect(machineCountRequests.length).toBe(1); | ||
// perform machine search | ||
await page.getByLabel("Search").locator("visible=true").type("doesnotexist"); | ||
await expect(page.getByRole("grid", { name: /Loading/i })).toBeHidden(); | ||
await expect( | ||
page.getByText(/No machines match the search criteria/) | ||
).toBeVisible(); | ||
// expect an additional single machine.list request | ||
await expect(machineListRequests.length).toBe(2); | ||
await expect(machineCountRequests.length).toBe(1); | ||
test("example test using runMAASCommand", async () => { | ||
await runMAASCommand("zones create", "name=zone-1"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters