mirror of
https://github.com/tale/headplane.git
synced 2026-07-26 07:48:14 +00:00
feat(ui): add support for showing existing tag options
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { isNoExpiry } from "~/utils/node-info";
|
||||
import { extractTagOwnerTags, isNoExpiry, sortAssignableTags } from "~/utils/node-info";
|
||||
|
||||
describe("isNoExpiry", () => {
|
||||
test("returns true for null", () => {
|
||||
@@ -27,3 +27,51 @@ describe("isNoExpiry", () => {
|
||||
expect(isNoExpiry("2020-01-01T00:00:00Z")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("extractTagOwnerTags", () => {
|
||||
test("reads tags from HuJSON tagOwners", () => {
|
||||
expect(
|
||||
extractTagOwnerTags(`{
|
||||
// comment
|
||||
"tagOwners": {
|
||||
"tag:prod": ["group:admins"],
|
||||
"tag:server": [],
|
||||
},
|
||||
}`),
|
||||
).toEqual(["tag:prod", "tag:server"]);
|
||||
});
|
||||
|
||||
test("ignores invalid policies", () => {
|
||||
expect(extractTagOwnerTags("not-json")).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sortAssignableTags", () => {
|
||||
test("unions assigned node tags with ACL tag owners", () => {
|
||||
expect(
|
||||
sortAssignableTags(
|
||||
[
|
||||
{
|
||||
id: "1",
|
||||
givenName: "node",
|
||||
name: "node",
|
||||
machineKey: "mkey:test",
|
||||
nodeKey: "nodekey:test",
|
||||
discoKey: "discokey:test",
|
||||
ipAddresses: [],
|
||||
tags: ["tag:used"],
|
||||
lastSeen: "",
|
||||
expiry: null,
|
||||
online: true,
|
||||
registerMethod: "REGISTER_METHOD_AUTH_KEY",
|
||||
createdAt: "",
|
||||
availableRoutes: [],
|
||||
approvedRoutes: [],
|
||||
subnetRoutes: [],
|
||||
},
|
||||
],
|
||||
'{"tagOwners":{"tag:declared":[]}}',
|
||||
),
|
||||
).toEqual(["tag:declared", "tag:used"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user