- Extract peer parsing and exit-node command logic into lib.js - Add ↗ button on peers that are ExitNodeOption candidates - Highlight active exit node in primary color - Add clear (×) button next to current exit node label - Add unit tests for parsePeers and makeExitNodeCommand
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import { test } from "node:test"
|
|
import assert from "node:assert"
|
|
import { parsePeers, makeExitNodeCommand } from "../tailscalectl/lib.js"
|
|
|
|
test("parsePeers extracts exitNode from ExitNodeOption", () => {
|
|
const peerMap = {
|
|
"peer-1": {
|
|
HostName: "router",
|
|
TailscaleIPs: ["100.64.0.1"],
|
|
Online: true,
|
|
ExitNodeOption: true
|
|
},
|
|
"peer-2": {
|
|
HostName: "laptop",
|
|
TailscaleIPs: ["100.64.0.2"],
|
|
Online: true,
|
|
ExitNodeOption: false
|
|
}
|
|
}
|
|
|
|
const peers = parsePeers(peerMap)
|
|
|
|
assert.strictEqual(peers[0].exitNode, true)
|
|
assert.strictEqual(peers[1].exitNode, false)
|
|
})
|
|
|
|
test("makeExitNodeCommand returns tailscale set command for hostname", () => {
|
|
const cmd = makeExitNodeCommand("router")
|
|
assert.deepStrictEqual(cmd, ["tailscale", "set", "--exit-node=router"])
|
|
})
|
|
|
|
test("makeExitNodeCommand with empty string clears exit node", () => {
|
|
const cmd = makeExitNodeCommand("")
|
|
assert.deepStrictEqual(cmd, ["tailscale", "set", "--exit-node="])
|
|
})
|