Explorar o código

cmd/derper,tstest/nettest: skip network-needing test in airplane mode

Not buying wifi on a short flight is a good way to find tests
that require network. Whoops.

Updates #cleanup

Change-Id: Ibe678e9c755d27269ad7206413ffe9971f07d298
Signed-off-by: Brad Fitzpatrick <[email protected]>
Brad Fitzpatrick hai 1 ano
pai
achega
1fe0983f2d
Modificáronse 2 ficheiros con 24 adicións e 0 borrados
  1. 3 0
      cmd/derper/bootstrap_dns_test.go
  2. 21 0
      tstest/nettest/nettest.go

+ 3 - 0
cmd/derper/bootstrap_dns_test.go

@@ -13,6 +13,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"tailscale.com/tstest"
 	"tailscale.com/tstest"
+	"tailscale.com/tstest/nettest"
 )
 )
 
 
 func BenchmarkHandleBootstrapDNS(b *testing.B) {
 func BenchmarkHandleBootstrapDNS(b *testing.B) {
@@ -55,6 +56,8 @@ func getBootstrapDNS(t *testing.T, q string) dnsEntryMap {
 }
 }
 
 
 func TestUnpublishedDNS(t *testing.T) {
 func TestUnpublishedDNS(t *testing.T) {
+	nettest.SkipIfNoNetwork(t)
+
 	const published = "login.tailscale.com"
 	const published = "login.tailscale.com"
 	const unpublished = "log.tailscale.io"
 	const unpublished = "log.tailscale.io"
 
 

+ 21 - 0
tstest/nettest/nettest.go

@@ -0,0 +1,21 @@
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+// Package nettest contains additional test helpers related to network state
+// that can't go into tstest for circular dependency reasons.
+package nettest
+
+import (
+	"testing"
+
+	"tailscale.com/net/netmon"
+)
+
+// SkipIfNoNetwork skips the test if it looks like there's no network
+// access.
+func SkipIfNoNetwork(t testing.TB) {
+	nm := netmon.NewStatic()
+	if !nm.InterfaceState().AnyInterfaceUp() {
+		t.Skip("skipping; test requires network but no interface is up")
+	}
+}