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

Function TestUpdater_createPeerUpdate

vpn/tunnel_internal_test.go:325–401  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

323}
324
325func TestUpdater_createPeerUpdate(t *testing.T) {
326 t.Parallel()
327
328 w1ID := uuid.UUID{1}
329 w2ID := uuid.UUID{2}
330 w1a1ID := uuid.UUID{4}
331 w2a1ID := uuid.UUID{5}
332 w1a1IP := netip.MustParseAddr("fd60:627a:a42b:0101::")
333 w2a1IP := netip.MustParseAddr("fd60:627a:a42b:0301::")
334
335 ctx := testutil.Context(t, testutil.WaitShort)
336
337 hsTime := time.Now().Add(-time.Minute).UTC()
338 updater := updater{
339 ctx: ctx,
340 netLoopDone: make(chan struct{}),
341 agents: map[uuid.UUID]agentWithPing{},
342 workspaces: map[uuid.UUID]tailnet.Workspace{},
343 conn: newFakeConn(tailnet.WorkspaceUpdate{}, hsTime),
344 }
345
346 update := updater.createPeerUpdateLocked(tailnet.WorkspaceUpdate{
347 UpsertedWorkspaces: []*tailnet.Workspace{
348 {ID: w1ID, Name: "w1", Status: proto.Workspace_STARTING},
349 },
350 UpsertedAgents: []*tailnet.Agent{
351 {
352 ID: w1a1ID, Name: "w1a1", WorkspaceID: w1ID,
353 Hosts: map[dnsname.FQDN][]netip.Addr{
354 "w1.coder.": {w1a1IP},
355 "w1a1.w1.me.coder.": {w1a1IP},
356 "w1a1.w1.testy.coder.": {w1a1IP},
357 },
358 },
359 },
360 DeletedWorkspaces: []*tailnet.Workspace{
361 {ID: w2ID, Name: "w2", Status: proto.Workspace_STOPPED},
362 },
363 DeletedAgents: []*tailnet.Agent{
364 {
365 ID: w2a1ID, Name: "w2a1", WorkspaceID: w2ID,
366 Hosts: map[dnsname.FQDN][]netip.Addr{
367 "w2.coder.": {w2a1IP},
368 "w2a1.w2.me.coder.": {w2a1IP},
369 "w2a1.w2.testy.coder.": {w2a1IP},
370 },
371 },
372 },
373 })
374 require.Len(t, update.UpsertedAgents, 1)
375 slices.SortFunc(update.UpsertedAgents[0].Fqdn, strings.Compare)
376 slices.SortFunc(update.DeletedAgents[0].Fqdn, strings.Compare)
377 require.Equal(t, update, &PeerUpdate{
378 UpsertedWorkspaces: []*Workspace{
379 {Id: w1ID[:], Name: "w1", Status: Workspace_Status(proto.Workspace_STARTING)},
380 },
381 UpsertedAgents: []*Agent{
382 {

Callers

nothing calls this directly

Calls 9

ContextFunction · 0.92
newFakeConnFunction · 0.85
Workspace_StatusTypeAlias · 0.70
AddMethod · 0.65
NewMethod · 0.65
LenMethod · 0.45
EqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected