本文整理汇总了Golang中internal/testenv.MustHaveExternalNetwork函数的典型用法代码示例。如果您正苦于以下问题:Golang MustHaveExternalNetwork函数的具体用法?Golang MustHaveExternalNetwork怎么用?Golang MustHaveExternalNetwork使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustHaveExternalNetwork函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestVendorTest2
func TestVendorTest2(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOPATH", tg.path("."))
tg.setenv("GO15VENDOREXPERIMENT", "1")
tg.run("get", "github.com/rsc/go-get-issue-11864")
// build -i should work
tg.run("build", "-i", "github.com/rsc/go-get-issue-11864")
tg.run("build", "-i", "github.com/rsc/go-get-issue-11864/t")
// test -i should work like build -i (golang.org/issue/11988)
tg.run("test", "-i", "github.com/rsc/go-get-issue-11864")
tg.run("test", "-i", "github.com/rsc/go-get-issue-11864/t")
// test should work too
tg.run("test", "github.com/rsc/go-get-issue-11864")
tg.run("test", "github.com/rsc/go-get-issue-11864/t")
// external tests should observe internal test exports (golang.org/issue/11977)
tg.run("test", "github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx2")
}
示例2: TestLookupNS
func TestLookupNS(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
for _, server := range nslookupTestServers {
ns, err := LookupNS(server)
if err != nil {
t.Errorf("failed %s: %s", server, err)
continue
}
if len(ns) == 0 {
t.Errorf("no results")
continue
}
expected, err := nslookupNS(server)
if err != nil {
t.Logf("skipping failed nslookup %s test: %s", server, err)
continue
}
sort.Sort(byHost(expected))
sort.Sort(byHost(ns))
if !reflect.DeepEqual(expected, ns) {
t.Errorf("different results %s:\texp:%v\tgot:%v", toJson(server), toJson(expected), ns)
}
}
}
示例3: TestVerifyHostname
func TestVerifyHostname(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
c, err := Dial("tcp", "www.google.com:https", nil)
if err != nil {
t.Fatal(err)
}
if err := c.VerifyHostname("www.google.com"); err != nil {
t.Fatalf("verify www.google.com: %v", err)
}
if err := c.VerifyHostname("www.yahoo.com"); err == nil {
t.Fatalf("verify www.yahoo.com succeeded")
}
c, err = Dial("tcp", "www.google.com:https", &Config{InsecureSkipVerify: true})
if err != nil {
t.Fatal(err)
}
if err := c.VerifyHostname("www.google.com"); err == nil {
t.Fatalf("verify www.google.com succeeded with InsecureSkipVerify=true")
}
if err := c.VerifyHostname("www.yahoo.com"); err == nil {
t.Fatalf("verify www.google.com succeeded with InsecureSkipVerify=true")
}
}
示例4: TestLookupTXT
func TestLookupTXT(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
for _, server := range nslookupTestServers {
txt, err := LookupTXT(server)
if err != nil {
t.Errorf("failed %s: %s", server, err)
continue
}
if len(txt) == 0 {
t.Errorf("no results")
continue
}
expected, err := nslookupTXT(server)
if err != nil {
t.Logf("skipping failed nslookup %s test: %s", server, err)
continue
}
sort.Strings(expected)
sort.Strings(txt)
if !reflect.DeepEqual(expected, txt) {
t.Errorf("different results %s:\texp:%v\tgot:%v", server, toJson(expected), toJson(txt))
}
}
}
示例5: TestVendorTest3
func TestVendorTest3(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOPATH", tg.path("."))
tg.run("get", "github.com/clsung/go-vendor-issue-14613")
tg.run("build", "-i", "github.com/clsung/go-vendor-issue-14613")
// test folder should work
tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613")
tg.run("test", "github.com/clsung/go-vendor-issue-14613")
// test with specified _test.go should work too
tg.cd(filepath.Join(tg.path("."), "src"))
tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613/vendor_test.go")
tg.run("test", "github.com/clsung/go-vendor-issue-14613/vendor_test.go")
// test with imported and not used
tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go")
tg.runFail("test", "github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go")
tg.grepStderr("imported and not used:", `should say "imported and not used"`)
}
示例6: TestLookupGmailNS
func TestLookupGmailNS(t *testing.T) {
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !*testIPv4 {
t.Skip("IPv4 is required")
}
for _, tt := range lookupGmailNSTests {
nss, err := LookupNS(tt.name)
if err != nil {
testenv.SkipFlakyNet(t)
t.Fatal(err)
}
if len(nss) == 0 {
t.Error("got no record")
}
for _, ns := range nss {
if !strings.HasSuffix(ns.Host, tt.host) {
t.Errorf("got %v; want a record containing %s", ns, tt.host)
}
}
}
}
示例7: TestLookupGoogleSRV
func TestLookupGoogleSRV(t *testing.T) {
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !*testIPv4 {
t.Skip("IPv4 is required")
}
for _, tt := range lookupGoogleSRVTests {
cname, srvs, err := LookupSRV(tt.service, tt.proto, tt.name)
if err != nil {
testenv.SkipFlakyNet(t)
t.Fatal(err)
}
if len(srvs) == 0 {
t.Error("got no record")
}
if !strings.HasSuffix(cname, tt.cname) {
t.Errorf("got %s; want %s", cname, tt.cname)
}
for _, srv := range srvs {
if !strings.HasSuffix(srv.Target, tt.target) {
t.Errorf("got %v; want a record containing %s", srv, tt.target)
}
}
}
}
示例8: TestProhibitionaryDialArg
func TestProhibitionaryDialArg(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
switch runtime.GOOS {
case "plan9":
t.Skipf("not supported on %s", runtime.GOOS)
}
if !supportsIPv4map {
t.Skip("mapping ipv4 address inside ipv6 address not supported")
}
ln, err := Listen("tcp", "[::]:0")
if err != nil {
t.Fatal(err)
}
defer ln.Close()
_, port, err := SplitHostPort(ln.Addr().String())
if err != nil {
t.Fatal(err)
}
for i, tt := range prohibitionaryDialArgTests {
c, err := Dial(tt.network, JoinHostPort(tt.address, port))
if err == nil {
c.Close()
t.Errorf("#%d: %v", i, err)
}
}
}
示例9: TestWildWildcardListener
func TestWildWildcardListener(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
switch runtime.GOOS {
case "plan9":
t.Skipf("not supported on %s", runtime.GOOS)
}
defer func() {
if p := recover(); p != nil {
t.Fatalf("panicked: %v", p)
}
}()
if ln, err := Listen("tcp", ""); err == nil {
ln.Close()
}
if ln, err := ListenPacket("udp", ""); err == nil {
ln.Close()
}
if ln, err := ListenTCP("tcp", nil); err == nil {
ln.Close()
}
if ln, err := ListenUDP("udp", nil); err == nil {
ln.Close()
}
if ln, err := ListenIP("ip:icmp", nil); err == nil {
ln.Close()
}
}
示例10: TestListenMulticastUDP
func TestListenMulticastUDP(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
ifcs, err := Interfaces()
if err != nil {
t.Skip(err.Error())
}
if len(ifcs) == 0 {
t.Skip("no network interfaces found")
}
var mifc *Interface
for _, ifc := range ifcs {
if ifc.Flags&FlagUp|FlagMulticast != FlagUp|FlagMulticast {
continue
}
mifc = &ifc
break
}
if mifc == nil {
t.Skipf("no multicast interfaces found")
}
c1, err := ListenMulticastUDP("udp4", mifc, &UDPAddr{IP: ParseIP("224.0.0.254")})
if err != nil {
t.Fatalf("multicast not working on %s", runtime.GOOS)
}
c1addr := c1.LocalAddr().(*UDPAddr)
if err != nil {
t.Fatal(err)
}
defer c1.Close()
c2, err := ListenUDP("udp4", &UDPAddr{IP: IPv4zero, Port: 0})
c2addr := c2.LocalAddr().(*UDPAddr)
if err != nil {
t.Fatal(err)
}
defer c2.Close()
n, err := c2.WriteToUDP([]byte("data"), c1addr)
if err != nil {
t.Fatal(err)
}
if n != 4 {
t.Fatalf("got %d; want 4", n)
}
n, err = c1.WriteToUDP([]byte("data"), c2addr)
if err != nil {
t.Fatal(err)
}
if n != 4 {
t.Fatalf("got %d; want 4", n)
}
}
示例11: TestGetSubmodules
func TestGetSubmodules(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOPATH", tg.path("."))
tg.run("get", "-d", "github.com/rsc/go-get-issue-12612")
tg.run("get", "-u", "-d", "github.com/rsc/go-get-issue-12612")
}
示例12: TestVendorGetUpdate
func TestVendorGetUpdate(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOPATH", tg.path("."))
tg.run("get", "github.com/rsc/go-get-issue-11864")
tg.run("get", "-u", "github.com/rsc/go-get-issue-11864")
}
示例13: TestIPv6MulticastListener
// TestIPv6MulticastListener tests both single and double listen to a
// test listener with same address family, same group address and same
// port.
func TestIPv6MulticastListener(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
switch runtime.GOOS {
case "plan9":
t.Skipf("not supported on %s", runtime.GOOS)
case "solaris":
t.Skipf("not supported on solaris, see issue 7399")
}
if !supportsIPv6 {
t.Skip("IPv6 is not supported")
}
if os.Getuid() != 0 {
t.Skip("must be root")
}
closer := func(cs []*UDPConn) {
for _, c := range cs {
if c != nil {
c.Close()
}
}
}
for _, ifi := range []*Interface{loopbackInterface(), nil} {
// Note that multicast interface assignment by system
// is not recommended because it usually relies on
// routing stuff for finding out an appropriate
// nexthop containing both network and link layer
// adjacencies.
if ifi == nil && !*testIPv6 {
continue
}
for _, tt := range ipv6MulticastListenerTests {
var err error
cs := make([]*UDPConn, 2)
if cs[0], err = ListenMulticastUDP(tt.net, ifi, tt.gaddr); err != nil {
t.Fatal(err)
}
if err := checkMulticastListener(cs[0], tt.gaddr.IP); err != nil {
closer(cs)
t.Fatal(err)
}
if cs[1], err = ListenMulticastUDP(tt.net, ifi, tt.gaddr); err != nil {
closer(cs)
t.Fatal(err)
}
if err := checkMulticastListener(cs[1], tt.gaddr.IP); err != nil {
closer(cs)
t.Fatal(err)
}
closer(cs)
}
}
}
示例14: TestGetSubmodules
func TestGetSubmodules(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOPATH", tg.path("."))
tg.run("get", "-d", "github.com/rsc/go-get-issue-12612")
tg.run("get", "-u", "-d", "github.com/rsc/go-get-issue-12612")
tg.mustExist(tg.path("src/github.com/rsc/go-get-issue-12612/vendor/golang.org/x/crypto/.git"))
}
示例15: TestIPv6LinkLocalUnicastTCP
func TestIPv6LinkLocalUnicastTCP(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
if !supportsIPv6 {
t.Skip("IPv6 is not supported")
}
for i, tt := range ipv6LinkLocalUnicastTCPTests {
ln, err := Listen(tt.network, tt.address)
if err != nil {
// It might return "LookupHost returned no
// suitable address" error on some platforms.
t.Log(err)
continue
}
ls, err := (&streamListener{Listener: ln}).newLocalServer()
if err != nil {
t.Fatal(err)
}
defer ls.teardown()
ch := make(chan error, 1)
handler := func(ls *localServer, ln Listener) { transponder(ln, ch) }
if err := ls.buildup(handler); err != nil {
t.Fatal(err)
}
if la, ok := ln.Addr().(*TCPAddr); !ok || !tt.nameLookup && la.Zone == "" {
t.Fatalf("got %v; expected a proper address with zone identifier", la)
}
c, err := Dial(tt.network, ls.Listener.Addr().String())
if err != nil {
t.Fatal(err)
}
defer c.Close()
if la, ok := c.LocalAddr().(*TCPAddr); !ok || !tt.nameLookup && la.Zone == "" {
t.Fatalf("got %v; expected a proper address with zone identifier", la)
}
if ra, ok := c.RemoteAddr().(*TCPAddr); !ok || !tt.nameLookup && ra.Zone == "" {
t.Fatalf("got %v; expected a proper address with zone identifier", ra)
}
if _, err := c.Write([]byte("TCP OVER IPV6 LINKLOCAL TEST")); err != nil {
t.Fatal(err)
}
b := make([]byte, 32)
if _, err := c.Read(b); err != nil {
t.Fatal(err)
}
for err := range ch {
t.Errorf("#%d: %v", i, err)
}
}
}