useCap is whether to use NodeAttrDefaultAutoUpdate (as opposed to the old DeprecatedDefaultAutoUpdate top-level MapResponse field).
(t *testing.T, useCap bool)
| 1495 | // useCap is whether to use NodeAttrDefaultAutoUpdate (as opposed to the old |
| 1496 | // DeprecatedDefaultAutoUpdate top-level MapResponse field). |
| 1497 | func testAutoUpdateDefaults(t *testing.T, useCap bool) { |
| 1498 | t.Cleanup(feature.HookCanAutoUpdate.SetForTest(func() bool { return true })) |
| 1499 | |
| 1500 | env := NewTestEnv(t) |
| 1501 | |
| 1502 | var ( |
| 1503 | modifyMu sync.Mutex |
| 1504 | modifyFirstMapResponse = func(*tailcfg.MapResponse, *tailcfg.MapRequest) {} |
| 1505 | ) |
| 1506 | env.Control.ModifyFirstMapResponse = func(mr *tailcfg.MapResponse, req *tailcfg.MapRequest) { |
| 1507 | modifyMu.Lock() |
| 1508 | defer modifyMu.Unlock() |
| 1509 | modifyFirstMapResponse(mr, req) |
| 1510 | } |
| 1511 | |
| 1512 | checkDefault := func(n *TestNode, want bool) error { |
| 1513 | enabled, ok := n.diskPrefs().AutoUpdate.Apply.Get() |
| 1514 | if !ok { |
| 1515 | return fmt.Errorf("auto-update for node is unset, should be set as %v", want) |
| 1516 | } |
| 1517 | if enabled != want { |
| 1518 | return fmt.Errorf("auto-update for node is %v, should be set as %v", enabled, want) |
| 1519 | } |
| 1520 | return nil |
| 1521 | } |
| 1522 | |
| 1523 | setDefaultAutoUpdate := func(send bool) { |
| 1524 | modifyMu.Lock() |
| 1525 | defer modifyMu.Unlock() |
| 1526 | modifyFirstMapResponse = func(mr *tailcfg.MapResponse, req *tailcfg.MapRequest) { |
| 1527 | if mr.Node == nil { |
| 1528 | mr.Node = &tailcfg.Node{} |
| 1529 | } |
| 1530 | if useCap { |
| 1531 | if mr.Node.CapMap == nil { |
| 1532 | mr.Node.CapMap = make(tailcfg.NodeCapMap) |
| 1533 | } |
| 1534 | mr.Node.CapMap[tailcfg.NodeAttrDefaultAutoUpdate] = []tailcfg.RawMessage{ |
| 1535 | tailcfg.RawMessage(fmt.Sprintf("%t", send)), |
| 1536 | } |
| 1537 | } else { |
| 1538 | mr.DeprecatedDefaultAutoUpdate = opt.NewBool(send) |
| 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | tests := []struct { |
| 1544 | desc string |
| 1545 | run func(t *testing.T, n *TestNode) |
| 1546 | }{ |
| 1547 | { |
| 1548 | desc: "tailnet-default-false", |
| 1549 | run: func(t *testing.T, n *TestNode) { |
| 1550 | |
| 1551 | // First the server sends "false", and client should remember that. |
| 1552 | setDefaultAutoUpdate(false) |
| 1553 | n.MustUp() |
| 1554 | n.AwaitRunning() |
no test coverage detected
searching dependent graphs…