MCPcopy Index your code
hub / github.com/coder/coder / TestNode

Function TestNode

tailnet/convert_test.go:20–91  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestNode(t *testing.T) {
21 t.Parallel()
22 testCases := []struct {
23 name string
24 node tailnet.Node
25 }{
26 {
27 name: "Zero",
28 },
29 {
30 name: "AllFields",
31 node: tailnet.Node{
32 ID: 33,
33 AsOf: time.Now(),
34 Key: key.NewNode().Public(),
35 DiscoKey: key.NewDisco().Public(),
36 PreferredDERP: 12,
37 DERPLatency: map[string]float64{
38 "1": 0.2,
39 "12": 0.3,
40 },
41 DERPForcedWebsocket: map[int]string{
42 1: "forced",
43 },
44 Addresses: []netip.Prefix{
45 netip.MustParsePrefix("10.0.0.0/8"),
46 netip.MustParsePrefix("ff80::aa:1/128"),
47 },
48 AllowedIPs: []netip.Prefix{
49 netip.MustParsePrefix("10.0.0.0/8"),
50 netip.MustParsePrefix("ff80::aa:1/128"),
51 },
52 Endpoints: []string{
53 "192.168.0.1:3305",
54 "[ff80::aa:1]:2049",
55 },
56 },
57 },
58 {
59 name: "dbtime",
60 node: tailnet.Node{
61 AsOf: dbtime.Now(),
62 },
63 },
64 }
65
66 for _, tc := range testCases {
67 t.Run(tc.name, func(t *testing.T) {
68 t.Parallel()
69 p, err := tailnet.NodeToProto(&tc.node)
70 require.NoError(t, err)
71
72 inv, err := tailnet.ProtoToNode(p)
73 require.NoError(t, err)
74 require.Equal(t, tc.node.ID, inv.ID)
75 require.True(t, tc.node.AsOf.Equal(inv.AsOf))
76 require.Equal(t, tc.node.Key, inv.Key)
77 require.Equal(t, tc.node.DiscoKey, inv.DiscoKey)

Callers

nothing calls this directly

Calls 5

NowFunction · 0.92
NodeToProtoFunction · 0.92
ProtoToNodeFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected