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

Function Test_nodeHasCap

wgengine/magicsock/magicsock_test.go:3592–3735  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3590}
3591
3592func Test_nodeHasCap(t *testing.T) {
3593 nodeAOnlyIPv4 := &tailcfg.Node{
3594 ID: 1,
3595 Addresses: []netip.Prefix{
3596 netip.MustParsePrefix("1.1.1.1/32"),
3597 },
3598 }
3599 nodeBOnlyIPv6 := nodeAOnlyIPv4.Clone()
3600 nodeBOnlyIPv6.Addresses[0] = netip.MustParsePrefix("::1/128")
3601
3602 nodeCOnlyIPv4 := &tailcfg.Node{
3603 ID: 2,
3604 Addresses: []netip.Prefix{
3605 netip.MustParsePrefix("2.2.2.2/32"),
3606 },
3607 }
3608 nodeDOnlyIPv6 := nodeCOnlyIPv4.Clone()
3609 nodeDOnlyIPv6.Addresses[0] = netip.MustParsePrefix("::2/128")
3610
3611 tests := []struct {
3612 name string
3613 filt *filter.Filter
3614 src tailcfg.NodeView
3615 dst tailcfg.NodeView
3616 cap tailcfg.PeerCapability
3617 want bool
3618 }{
3619 {
3620 name: "match-v4",
3621 filt: filter.New([]filtertype.Match{
3622 {
3623 Srcs: []netip.Prefix{netip.MustParsePrefix("2.2.2.2/32")},
3624 Caps: []filtertype.CapMatch{
3625 {
3626 Dst: netip.MustParsePrefix("1.1.1.1/32"),
3627 Cap: tailcfg.PeerCapabilityRelayTarget,
3628 },
3629 },
3630 },
3631 }, nil, nil, nil, nil, nil),
3632 src: nodeCOnlyIPv4.View(),
3633 dst: nodeAOnlyIPv4.View(),
3634 cap: tailcfg.PeerCapabilityRelayTarget,
3635 want: true,
3636 },
3637 {
3638 name: "match-v6",
3639 filt: filter.New([]filtertype.Match{
3640 {
3641 Srcs: []netip.Prefix{netip.MustParsePrefix("::2/128")},
3642 Caps: []filtertype.CapMatch{
3643 {
3644 Dst: netip.MustParsePrefix("::1/128"),
3645 Cap: tailcfg.PeerCapabilityRelayTarget,
3646 },
3647 },
3648 },
3649 }, nil, nil, nil, nil, nil),

Callers

nothing calls this directly

Calls 7

CloneMethod · 0.95
ViewMethod · 0.95
NewFunction · 0.92
nodeHasCapFunction · 0.85
ViewMethod · 0.65
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…