TestNodeFileFormat verifies that ReadNodeFile can parse a fixed JSON literal, ensuring we don't accidentally change the on-disk format.
(t *testing.T)
| 50 | // TestNodeFileFormat verifies that ReadNodeFile can parse a fixed JSON literal, |
| 51 | // ensuring we don't accidentally change the on-disk format. |
| 52 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…