MCPcopy Index your code
hub / github.com/tailscale/tailscale / TestNodeFileWriteFormat

Function TestNodeFileWriteFormat

control/tsp/nodefile_test.go:85–116  ·  view source on GitHub ↗

TestNodeFileWriteFormat verifies that WriteNodeFile produces the expected JSON field names.

(t *testing.T)

Source from the content-addressed store, hash-verified

83// TestNodeFileWriteFormat verifies that WriteNodeFile produces the expected
84// JSON field names.
85func TestNodeFileWriteFormat(t *testing.T) {
86 dir := t.TempDir()
87 path := filepath.Join(dir, "node.json")
88
89 nf := NodeFile{
90 NodeKey: key.NewNode(),
91 MachineKey: key.NewMachine(),
92 ServerInfo: ServerInfo{
93 URL: "https://example.com",
94 Key: key.NewMachine().Public(),
95 },
96 }
97
98 if err := WriteNodeFile(path, nf); err != nil {
99 t.Fatalf("WriteNodeFile: %v", err)
100 }
101
102 data, err := os.ReadFile(path)
103 if err != nil {
104 t.Fatal(err)
105 }
106
107 var raw map[string]json.RawMessage
108 if err := json.Unmarshal(data, &raw); err != nil {
109 t.Fatalf("parsing written JSON: %v", err)
110 }
111 for _, field := range []string{"node_key", "machine_key", "server_url", "server_key"} {
112 if _, ok := raw[field]; !ok {
113 t.Errorf("missing JSON field %q in written file", field)
114 }
115 }
116}

Callers

nothing calls this directly

Calls 9

NewNodeFunction · 0.92
NewMachineFunction · 0.92
WriteNodeFileFunction · 0.85
TempDirMethod · 0.65
FatalfMethod · 0.65
ReadFileMethod · 0.65
FatalMethod · 0.65
ErrorfMethod · 0.65
PublicMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…