(t *testing.T)
| 36 | } |
| 37 | |
| 38 | func TestIsNetstackRouter(t *testing.T) { |
| 39 | tests := []struct { |
| 40 | name string |
| 41 | conf wgengine.Config |
| 42 | setNetstackRouter bool |
| 43 | want bool |
| 44 | }{ |
| 45 | { |
| 46 | name: "no_netstack", |
| 47 | conf: wgengine.Config{ |
| 48 | Tun: newFakeOSTUN(), |
| 49 | Router: newFakeOSRouter(), |
| 50 | }, |
| 51 | want: false, |
| 52 | }, |
| 53 | { |
| 54 | name: "netstack", |
| 55 | conf: wgengine.Config{}, |
| 56 | want: true, |
| 57 | }, |
| 58 | { |
| 59 | name: "hybrid_netstack", |
| 60 | conf: wgengine.Config{ |
| 61 | Tun: newFakeOSTUN(), |
| 62 | Router: newFakeOSRouter(), |
| 63 | }, |
| 64 | setNetstackRouter: true, |
| 65 | want: true, |
| 66 | }, |
| 67 | } |
| 68 | for _, tt := range tests { |
| 69 | t.Run(tt.name, func(t *testing.T) { |
| 70 | sys := tsd.NewSystem() |
| 71 | if tt.setNetstackRouter { |
| 72 | sys.NetstackRouter.Set(true) |
| 73 | } |
| 74 | conf := tt.conf |
| 75 | conf.SetSubsystem = sys.Set |
| 76 | conf.HealthTracker = sys.HealthTracker.Get() |
| 77 | conf.Metrics = sys.UserMetricsRegistry() |
| 78 | conf.EventBus = sys.Bus.Get() |
| 79 | e, err := wgengine.NewUserspaceEngine(logger.Discard, conf) |
| 80 | if err != nil { |
| 81 | t.Fatal(err) |
| 82 | } |
| 83 | defer e.Close() |
| 84 | if got := sys.IsNetstackRouter(); got != tt.want { |
| 85 | t.Errorf("IsNetstackRouter = %v; want %v", got, tt.want) |
| 86 | } |
| 87 | }) |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | func newFakeOSRouter() router.Router { |
| 92 | return someRandoOSRouter{router.NewFake(logger.Discard)} |
nothing calls this directly
no test coverage detected
searching dependent graphs…