refactor: add getStatusCommand pure helper + test (TDD step 2 — prepares low-duty-cycle status calls)
This commit is contained in:
parent
6b71197770
commit
9dd73b6d55
2 changed files with 14 additions and 2 deletions
|
|
@ -103,6 +103,11 @@ function buildToggleCommand(isConnected) {
|
||||||
return isConnected ? ["tailscale", "down"] : ["tailscale", "up"]
|
return isConnected ? ["tailscale", "down"] : ["tailscale", "up"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Single source of truth for the status command used for on-demand and post-action verification.
|
||||||
|
function getStatusCommand() {
|
||||||
|
return ["tailscale", "status", "--json"]
|
||||||
|
}
|
||||||
|
|
||||||
function errorMessage(cmd) {
|
function errorMessage(cmd) {
|
||||||
var messages = {
|
var messages = {
|
||||||
"up": "Failed to connect to Tailscale",
|
"up": "Failed to connect to Tailscale",
|
||||||
|
|
@ -128,5 +133,5 @@ function formatError(action, detail) {
|
||||||
|
|
||||||
// CommonJS export for Node.js tests (ignored by QML)
|
// CommonJS export for Node.js tests (ignored by QML)
|
||||||
if (typeof module !== "undefined" && module.exports) {
|
if (typeof module !== "undefined" && module.exports) {
|
||||||
module.exports = { parsePeers, makeExitNodeCommand, findActiveExitNode, errorMessage, formatError, validateClipboardTool, buildCopyCommand, nextClipboardTool, allClipboardTools, buildToggleCommand, parseStatusResult, getStrings, shouldShowClearExitNode, isActiveExitNode }
|
module.exports = { parsePeers, makeExitNodeCommand, findActiveExitNode, errorMessage, formatError, getStatusCommand, validateClipboardTool, buildCopyCommand, nextClipboardTool, allClipboardTools, buildToggleCommand, parseStatusResult, getStrings, shouldShowClearExitNode, isActiveExitNode }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { test } from "node:test"
|
import { test } from "node:test"
|
||||||
import assert from "node:assert"
|
import assert from "node:assert"
|
||||||
import lib from "../tailscalectl/lib.js"
|
import lib from "../tailscalectl/lib.js"
|
||||||
const { parsePeers, makeExitNodeCommand, findActiveExitNode, errorMessage, formatError, validateClipboardTool, buildCopyCommand, nextClipboardTool, allClipboardTools, buildToggleCommand, parseStatusResult, getStrings, shouldShowClearExitNode, isActiveExitNode } = lib
|
const { parsePeers, makeExitNodeCommand, findActiveExitNode, errorMessage, formatError, getStatusCommand, validateClipboardTool, buildCopyCommand, nextClipboardTool, allClipboardTools, buildToggleCommand, parseStatusResult, getStrings, shouldShowClearExitNode, isActiveExitNode } = lib
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test coverage note for #48:
|
* Test coverage note for #48:
|
||||||
|
|
@ -260,3 +260,10 @@ test("formatError handles empty or falsy detail gracefully", () => {
|
||||||
assert.strictEqual(formatError("down", ""), "Failed to disconnect from Tailscale")
|
assert.strictEqual(formatError("down", ""), "Failed to disconnect from Tailscale")
|
||||||
assert.strictEqual(formatError("connect", null), "Failed to connect to Tailscale")
|
assert.strictEqual(formatError("connect", null), "Failed to connect to Tailscale")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// --- getStatusCommand (new pure helper for low-duty-cycle architecture) ---
|
||||||
|
|
||||||
|
test("getStatusCommand returns the canonical tailscale status --json argv", () => {
|
||||||
|
const cmd = getStatusCommand()
|
||||||
|
assert.deepStrictEqual(cmd, ["tailscale", "status", "--json"])
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue