MCPcopy
hub / github.com/tailscale/tailscale / TestNodeFileFormat

Function TestNodeFileFormat

control/tsp/nodefile_test.go:52–81  ·  view source on GitHub ↗

TestNodeFileFormat verifies that ReadNodeFile can parse a fixed JSON literal, ensuring we don't accidentally change the on-disk format.

(t *testing.T)

Source from the content-addressed store, hash-verified

50// TestNodeFileFormat verifies that ReadNodeFile can parse a fixed JSON literal,
51// ensuring we don't accidentally change the on-disk format.
52func TestNodeFileFormat(t *testing.T) {
53 const fileContents = `{
54 "node_key": "privkey:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
55 "machine_key": "privkey:fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210",
56 "server_url": "https://controlplane.tailscale.com",
57 "server_key": "mkey:1111111111111111111111111111111111111111111111111111111111111111"
58}`
59 dir := t.TempDir()
60 path := filepath.Join(dir, "node.json")
61 if err := os.WriteFile(path, []byte(fileContents), 0600); err != nil {
62 t.Fatal(err)
63 }
64
65 nf, err := ReadNodeFile(path)
66 if err != nil {
67 t.Fatalf("ReadNodeFile: %v", err)
68 }
69 if nf.NodeKey.IsZero() {
70 t.Error("node key is zero")
71 }
72 if nf.MachineKey.IsZero() {
73 t.Error("machine key is zero")
74 }
75 if nf.URL != "https://controlplane.tailscale.com" {
76 t.Errorf("server URL = %q", nf.URL)
77 }
78 if nf.ServerInfo.Key.IsZero() {
79 t.Error("server key is zero")
80 }
81}
82
83// TestNodeFileWriteFormat verifies that WriteNodeFile produces the expected
84// JSON field names.

Callers

nothing calls this directly

Calls 8

ReadNodeFileFunction · 0.85
TempDirMethod · 0.65
WriteFileMethod · 0.65
FatalMethod · 0.65
FatalfMethod · 0.65
IsZeroMethod · 0.65
ErrorMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…