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

Function TestSetNodeCapMap

tstest/integration/capmap_test.go:98–145  ·  view source on GitHub ↗

TestSetNodeCapMap tests that SetNodeCapMap updates are propagated to peers.

(t *testing.T)

Source from the content-addressed store, hash-verified

96
97// TestSetNodeCapMap tests that SetNodeCapMap updates are propagated to peers.
98func TestSetNodeCapMap(t *testing.T) {
99 tstest.Parallel(t)
100 env := NewTestEnv(t)
101
102 n1 := NewTestNode(t, env)
103 d1 := n1.StartDaemon()
104 n1.AwaitListening()
105 n1.MustUp()
106 n1.AwaitRunning()
107
108 nodes := env.Control.AllNodes()
109 if len(nodes) != 1 {
110 t.Fatalf("expected 1 node, got %d nodes", len(nodes))
111 }
112 node1 := nodes[0]
113
114 // Set initial CapMap.
115 caps := make(tailcfg.NodeCapMap)
116 caps["test:state"] = []tailcfg.RawMessage{`"initial"`}
117 env.Control.SetNodeCapMap(node1.Key, caps)
118
119 // Start second node and verify it sees the first node's CapMap.
120 n2 := NewTestNode(t, env)
121 d2 := n2.StartDaemon()
122 n2.AwaitListening()
123 n2.MustUp()
124 n2.AwaitRunning()
125
126 if err := tstest.WaitFor(5*time.Second, func() error {
127 st := n2.MustStatus()
128 if len(st.Peer) == 0 {
129 return errors.New("no peers")
130 }
131 p := st.Peer[st.Peers()[0]]
132 if p.CapMap == nil || p.CapMap["test:state"] == nil {
133 return errors.New("peer CapMap not set")
134 }
135 if string(p.CapMap["test:state"][0]) != `"initial"` {
136 return errors.New("wrong CapMap value")
137 }
138 return nil
139 }); err != nil {
140 t.Fatal(err)
141 }
142
143 d1.MustCleanShutdown(t)
144 d2.MustCleanShutdown(t)
145}

Callers

nothing calls this directly

Calls 15

StartDaemonMethod · 0.95
AwaitListeningMethod · 0.95
MustUpMethod · 0.95
AwaitRunningMethod · 0.95
MustStatusMethod · 0.95
ParallelFunction · 0.92
WaitForFunction · 0.92
NewTestEnvFunction · 0.85
NewTestNodeFunction · 0.85
AllNodesMethod · 0.80
SetNodeCapMapMethod · 0.80
MustCleanShutdownMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…