MCPcopy Create free account
hub / github.com/tailscale/tailscale / testAutoUpdateDefaults

Function testAutoUpdateDefaults

tstest/integration/integration_test.go:1497–1625  ·  view source on GitHub ↗

useCap is whether to use NodeAttrDefaultAutoUpdate (as opposed to the old DeprecatedDefaultAutoUpdate top-level MapResponse field).

(t *testing.T, useCap bool)

Source from the content-addressed store, hash-verified

1495// useCap is whether to use NodeAttrDefaultAutoUpdate (as opposed to the old
1496// DeprecatedDefaultAutoUpdate top-level MapResponse field).
1497func 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()

Callers 2

TestAutoUpdateDefaultsFunction · 0.85

Calls 15

diskPrefsMethod · 0.95
MustUpMethod · 0.95
AwaitRunningMethod · 0.95
MustDownMethod · 0.95
TailscaleForOutputMethod · 0.95
StartDaemonMethod · 0.95
AwaitRespondingMethod · 0.95
RawMessageTypeAlias · 0.92
NewBoolFunction · 0.92
NewTestEnvFunction · 0.85
NewTestNodeFunction · 0.85
CombinedOutputMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…