コード例 #1
0
func TestConnUnicastSocketOptions(t *testing.T) {
	switch runtime.GOOS {
	case "plan9", "solaris", "windows":
		t.Skipf("not supported on %q", runtime.GOOS)
	}
	if !supportsIPv6 {
		t.Skip("ipv6 is not supported")
	}

	ln, err := net.Listen("tcp6", "[::1]:0")
	if err != nil {
		t.Fatalf("net.Listen failed: %v", err)
	}
	defer ln.Close()

	done := make(chan bool)
	go acceptor(t, ln, done)

	c, err := net.Dial("tcp6", ln.Addr().String())
	if err != nil {
		t.Fatalf("net.Dial failed: %v", err)
	}
	defer c.Close()

	testUnicastSocketOptions(t, ipv6.NewConn(c))

	<-done
}
コード例 #2
0
ファイル: os_test.go プロジェクト: duhaibo0404/go-1
func TestStatStdin(t *testing.T) {
	switch runtime.GOOS {
	case "android", "plan9":
		t.Skipf("%s doesn't have /bin/sh", runtime.GOOS)
	}

	testenv.MustHaveExec(t)

	if Getenv("GO_WANT_HELPER_PROCESS") == "1" {
		st, err := Stdin.Stat()
		if err != nil {
			t.Fatalf("Stat failed: %v", err)
		}
		fmt.Println(st.Mode() & ModeNamedPipe)
		Exit(0)
	}

	var cmd *osexec.Cmd
	if runtime.GOOS == "windows" {
		cmd = osexec.Command("cmd", "/c", "echo output | "+Args[0]+" -test.run=TestStatStdin")
	} else {
		cmd = osexec.Command("/bin/sh", "-c", "echo output | "+Args[0]+" -test.run=TestStatStdin")
	}
	cmd.Env = append(Environ(), "GO_WANT_HELPER_PROCESS=1")

	output, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatalf("Failed to spawn child process: %v %q", err, string(output))
	}

	// result will be like "prw-rw-rw"
	if len(output) < 1 || output[0] != 'p' {
		t.Fatalf("Child process reports stdin is not pipe '%v'", string(output))
	}
}
コード例 #3
0
ファイル: os_test.go プロジェクト: duhaibo0404/go-1
func TestLongSymlink(t *testing.T) {
	switch runtime.GOOS {
	case "android", "plan9", "nacl":
		t.Skipf("skipping on %s", runtime.GOOS)
	case "windows":
		if !supportsSymlinks {
			t.Skipf("skipping on %s", runtime.GOOS)
		}
	}
	defer chtmpdir(t)()
	s := "0123456789abcdef"
	// Long, but not too long: a common limit is 255.
	s = s + s + s + s + s + s + s + s + s + s + s + s + s + s + s
	from := "longsymlinktestfrom"
	Remove(from) // Just in case.
	err := Symlink(s, from)
	if err != nil {
		t.Fatalf("symlink %q, %q failed: %v", s, from, err)
	}
	defer Remove(from)
	r, err := Readlink(from)
	if err != nil {
		t.Fatalf("readlink %q failed: %v", from, err)
	}
	if r != s {
		t.Fatalf("after symlink %q != %q", r, s)
	}
}
コード例 #4
0
ファイル: bridge_linux_test.go プロジェクト: Safe3/oz
func Test_NewBridge(t *testing.T) {
	tl := &testLink{}

	br, err := NewBridge()
	if err != nil {
		t.Fatalf("NewBridge() failed to run: %s", err)
	}

	brName := br.NetInterface().Name
	if err := tl.prepTestLink(brName, "bridge"); err != nil {
		t.Skipf("NewBridge test requries external command: %v", err)
	}

	if _, err := net.InterfaceByName(brName); err != nil {
		tl.teardown()
		t.Fatalf("Could not find %s on the host: %s", brName, err)
	}

	testRes, err := linkInfo(brName, "bridge")
	if err != nil {
		tl.teardown()
		t.Fatalf("Failed to list %s operation mode: %s", brName, err)
	}

	if testRes.linkType != "bridge" {
		tl.teardown()
		t.Fatalf("NewBridge() failed: expected linktype bridge, returned %s", testRes.linkType)
	}

	if err := tl.teardown(); err != nil {
		t.Fatalf("testLink.teardown failed: %v", err)
	} else {
		time.Sleep(10 * time.Millisecond)
	}
}
コード例 #5
0
ファイル: icmp_test.go プロジェクト: anlaneg/socketplane
func TestSetICMPFilter(t *testing.T) {
	switch runtime.GOOS {
	case "nacl", "plan9", "solaris", "windows":
		t.Skipf("not supported on %s", runtime.GOOS)
	}
	if !supportsIPv6 {
		t.Skip("ipv6 is not supported")
	}
	if m, ok := nettest.SupportsRawIPSocket(); !ok {
		t.Skip(m)
	}

	c, err := net.ListenPacket("ip6:ipv6-icmp", "::1")
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()

	p := ipv6.NewPacketConn(c)

	var f ipv6.ICMPFilter
	f.SetAll(true)
	f.Accept(ipv6.ICMPTypeEchoRequest)
	f.Accept(ipv6.ICMPTypeEchoReply)
	if err := p.SetICMPFilter(&f); err != nil {
		t.Fatal(err)
	}
	kf, err := p.ICMPFilter()
	if err != nil {
		t.Fatal(err)
	}
	if !reflect.DeepEqual(kf, &f) {
		t.Fatalf("got %#v; want %#v", kf, f)
	}
}
コード例 #6
0
func TestConnUnicastSocketOptions(t *testing.T) {
	switch runtime.GOOS {
	case "nacl", "plan9":
		t.Skipf("not supported on %s", runtime.GOOS)
	}
	ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
	if ifi == nil {
		t.Skipf("not available on %s", runtime.GOOS)
	}

	ln, err := net.Listen("tcp4", "127.0.0.1:0")
	if err != nil {
		t.Fatal(err)
	}
	defer ln.Close()

	done := make(chan bool)
	go acceptor(t, ln, done)

	c, err := net.Dial("tcp4", ln.Addr().String())
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()

	testUnicastSocketOptions(t, ipv4.NewConn(c))

	<-done
}
コード例 #7
0
func TestRawConnUnicastSocketOptions(t *testing.T) {
	switch runtime.GOOS {
	case "nacl", "plan9":
		t.Skipf("not supported on %s", runtime.GOOS)
	}
	if m, ok := nettest.SupportsRawIPSocket(); !ok {
		t.Skip(m)
	}
	ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
	if ifi == nil {
		t.Skipf("not available on %s", runtime.GOOS)
	}

	c, err := net.ListenPacket("ip4:icmp", "127.0.0.1")
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()

	r, err := ipv4.NewRawConn(c)
	if err != nil {
		t.Fatal(err)
	}

	testUnicastSocketOptions(t, r)
}
コード例 #8
0
ファイル: timeout_test.go プロジェクト: 29decibel/golang
// TestWriteDeadlineBufferAvailable tests that write deadlines work, even
// if there's buffer space available to write.
func TestWriteDeadlineBufferAvailable(t *testing.T) {
	switch runtime.GOOS {
	case "plan9":
		t.Skipf("skipping test on %q", runtime.GOOS)
	}

	ln := newLocalListener(t)
	defer ln.Close()

	servec := make(chan copyRes)
	go func() {
		c, err := ln.Accept()
		if err != nil {
			t.Fatalf("Accept: %v", err)
		}
		defer c.Close()
		c.SetWriteDeadline(time.Now().Add(-5 * time.Second)) // in the past
		n, err := c.Write([]byte{'x'})
		servec <- copyRes{n: int64(n), err: err}
	}()

	c, err := Dial("tcp", ln.Addr().String())
	if err != nil {
		t.Fatalf("Dial: %v", err)
	}
	defer c.Close()
	res := <-servec
	if res.n != 0 {
		t.Errorf("Write = %d; want 0", res.n)
	}
	if !isTimeout(res.err) {
		t.Errorf("Write error = %v; want timeout", res.err)
	}
}
コード例 #9
0
ファイル: timeout_test.go プロジェクト: 29decibel/golang
// TestAcceptDeadlineConnectionAvailable tests that accept deadlines work, even
// if there's incoming connections available.
func TestAcceptDeadlineConnectionAvailable(t *testing.T) {
	switch runtime.GOOS {
	case "plan9":
		t.Skipf("skipping test on %q", runtime.GOOS)
	}

	ln := newLocalListener(t).(*TCPListener)
	defer ln.Close()

	go func() {
		c, err := Dial("tcp", ln.Addr().String())
		if err != nil {
			t.Fatalf("Dial: %v", err)
		}
		defer c.Close()
		var buf [1]byte
		c.Read(buf[:]) // block until the connection or listener is closed
	}()
	time.Sleep(10 * time.Millisecond)
	ln.SetDeadline(time.Now().Add(-5 * time.Second)) // in the past
	c, err := ln.Accept()
	if err == nil {
		defer c.Close()
	}
	if !isTimeout(err) {
		t.Fatalf("Accept: got %v; want timeout", err)
	}
}
コード例 #10
0
ファイル: timeout_test.go プロジェクト: 29decibel/golang
func TestDeadlineReset(t *testing.T) {
	switch runtime.GOOS {
	case "plan9":
		t.Skipf("skipping test on %q", runtime.GOOS)
	}
	ln, err := Listen("tcp", "127.0.0.1:0")
	if err != nil {
		t.Fatal(err)
	}
	defer ln.Close()
	tl := ln.(*TCPListener)
	tl.SetDeadline(time.Now().Add(1 * time.Minute))
	tl.SetDeadline(noDeadline) // reset it
	errc := make(chan error, 1)
	go func() {
		_, err := ln.Accept()
		errc <- err
	}()
	select {
	case <-time.After(50 * time.Millisecond):
		// Pass.
	case err := <-errc:
		// Accept should never return; we never
		// connected to it.
		t.Errorf("unexpected return from Accept; err=%v", err)
	}
}
コード例 #11
0
ファイル: timeout_test.go プロジェクト: 29decibel/golang
func TestTimeoutAccept(t *testing.T) {
	switch runtime.GOOS {
	case "plan9":
		t.Skipf("skipping test on %q", runtime.GOOS)
	}
	ln, err := Listen("tcp", "127.0.0.1:0")
	if err != nil {
		t.Fatal(err)
	}
	defer ln.Close()
	tl := ln.(*TCPListener)
	tl.SetDeadline(time.Now().Add(100 * time.Millisecond))
	errc := make(chan error, 1)
	go func() {
		_, err := ln.Accept()
		errc <- err
	}()
	select {
	case <-time.After(1 * time.Second):
		// Accept shouldn't block indefinitely
		t.Errorf("Accept didn't return in an expected time")
	case <-errc:
		// Pass.
	}
}
コード例 #12
0
ファイル: timeout_test.go プロジェクト: 29decibel/golang
func TestWriteTimeout(t *testing.T) {
	switch runtime.GOOS {
	case "plan9":
		t.Skipf("skipping test on %q", runtime.GOOS)
	}

	ln := newLocalListener(t)
	defer ln.Close()
	c, err := DialTCP("tcp", nil, ln.Addr().(*TCPAddr))
	if err != nil {
		t.Fatalf("Connect: %v", err)
	}
	defer c.Close()
	c.SetDeadline(time.Now().Add(time.Hour))
	c.SetWriteDeadline(time.Now().Add(-1 * time.Second))
	buf := make([]byte, 4096)
	writeUntilTimeout := func() {
		for {
			_, err := c.Write(buf)
			if err != nil {
				if isTimeout(err) {
					return
				}
				t.Fatalf("Write: expected err %v, got %v", errTimeout, err)
			}
		}
	}
	writeUntilTimeout()
	c.SetDeadline(time.Now().Add(10 * time.Millisecond))
	writeUntilTimeout()
	writeUntilTimeout()
	c.SetWriteDeadline(noDeadline)
	c.SetReadDeadline(time.Now().Add(-1 * time.Second))
	errc := make(chan error)
	go func() {
		for {
			_, err := c.Write(buf)
			if err != nil {
				errc <- err
			}
		}
	}()
	time.Sleep(100 * time.Millisecond)
	select {
	case err := <-errc:
		t.Fatalf("Expected Write() to not return, but it returned with %v\n", err)
	default:
	}
	c.Close()
	switch nerr := <-errc; err := nerr.(type) {
	case *OpError:
		if err.Err != errClosing {
			t.Fatalf("Write: expected err %v, got %v", errClosing, err)
		}
	default:
		if err != errClosing {
			t.Fatalf("Write: expected err %v, got %v", errClosing, err)
		}
	}
}
コード例 #13
0
ファイル: server_test.go プロジェクト: kostyll/gccpy
func TestSeqpacketConnServer(t *testing.T) {
	if runtime.GOOS != "linux" {
		t.Skipf("skipping test on %q", runtime.GOOS)
	}

	for _, tt := range seqpacketConnServerTests {
		listening := make(chan string)
		done := make(chan int)
		switch tt.net {
		case "unixpacket":
			os.Remove(tt.saddr)
			os.Remove(tt.caddr)
		}

		go runStreamConnServer(t, tt.net, tt.saddr, listening, done)
		taddr := <-listening // wait for server to start

		runStreamConnClient(t, tt.net, taddr, tt.empty)
		<-done // make sure server stopped

		switch tt.net {
		case "unixpacket":
			os.Remove(tt.saddr)
			os.Remove(tt.caddr)
		}
	}
}
コード例 #14
0
// pulling library/hello-world should show verified message
func TestPullVerified(t *testing.T) {
	t.Skip("Skipping hub dependent test")

	// Image must be pulled from central repository to get verified message
	// unless keychain is manually updated to contain the daemon's sign key.

	verifiedName := "hello-world"
	defer deleteImages(verifiedName)

	// pull it
	expected := "The image you are pulling has been verified"
	pullCmd := exec.Command(dockerBinary, "pull", verifiedName)
	if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || !strings.Contains(out, expected) {
		if err != nil || exitCode != 0 {
			t.Skipf("pulling the '%s' image from the registry has failed: %s", verifiedName, err)
		}
		t.Fatalf("pulling a verified image failed. expected: %s\ngot: %s, %v", expected, out, err)
	}

	// pull it again
	pullCmd = exec.Command(dockerBinary, "pull", verifiedName)
	if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || strings.Contains(out, expected) {
		if err != nil || exitCode != 0 {
			t.Skipf("pulling the '%s' image from the registry has failed: %s", verifiedName, err)
		}
		t.Fatalf("pulling a verified image failed. unexpected verify message\ngot: %s, %v", out, err)
	}

	logDone("pull - pull verified")
}
コード例 #15
0
ファイル: os_haxe_test.go プロジェクト: joao-parana/tardisgo
func TestStartProcess(t *testing.T) {
	switch runtime.GOOS {
	case "android", "nacl":
		t.Skipf("skipping on %s", runtime.GOOS)
		return
	}

	var dir, cmd string
	var args []string
	if runtime.GOOS == "windows" {
		cmd = Getenv("COMSPEC")
		dir = Getenv("SystemRoot")
		args = []string{"/c", "cd"}
	} else {
		cmd = "/bin/pwd"
		dir = "/"
		args = []string{}
	}
	cmddir, cmdbase := filepath.Split(cmd)
	args = append([]string{cmdbase}, args...)
	// Test absolute executable path.
	exec(t, dir, cmd, args, dir)
	// Test relative executable path.
	exec(t, cmddir, cmdbase, args, cmddir)
}
コード例 #16
0
ファイル: pprof_test.go プロジェクト: amitarya/gcc
func parseProfile(t *testing.T, bytes []byte, f func(uintptr, []uintptr)) {
	// Convert []byte to []uintptr.
	l := len(bytes) / int(unsafe.Sizeof(uintptr(0)))
	val := *(*[]uintptr)(unsafe.Pointer(&bytes))
	val = val[:l]

	// 5 for the header, 2 for the per-sample header on at least one sample, 3 for the trailer.
	if l < 5+2+3 {
		t.Logf("profile too short: %#x", val)
		if badOS[runtime.GOOS] {
			t.Skipf("ignoring failure on %s; see golang.org/issue/6047", runtime.GOOS)
			return
		}
		t.FailNow()
	}

	hd, val, tl := val[:5], val[5:l-3], val[l-3:]
	if hd[0] != 0 || hd[1] != 3 || hd[2] != 0 || hd[3] != 1e6/100 || hd[4] != 0 {
		t.Fatalf("unexpected header %#x", hd)
	}

	if tl[0] != 0 || tl[1] != 1 || tl[2] != 0 {
		t.Fatalf("malformed end-of-data marker %#x", tl)
	}

	for len(val) > 0 {
		if len(val) < 2 || val[0] < 1 || val[1] < 1 || uintptr(len(val)) < 2+val[1] {
			t.Fatalf("malformed profile.  leftover: %#x", val)
		}
		f(val[0], val[2:2+val[1]])
		val = val[2+val[1]:]
	}
}
コード例 #17
0
func testUnicastSocketOptions(t *testing.T, c testIPv4UnicastConn) {
	tos := iana.DiffServCS0 | iana.NotECNTransport
	switch runtime.GOOS {
	case "windows":
		// IP_TOS option is supported on Windows 8 and beyond.
		t.Skipf("not supported on %s", runtime.GOOS)
	}

	if err := c.SetTOS(tos); err != nil {
		t.Fatal(err)
	}
	if v, err := c.TOS(); err != nil {
		t.Fatal(err)
	} else if v != tos {
		t.Fatalf("got %v; want %v", v, tos)
	}
	const ttl = 255
	if err := c.SetTTL(ttl); err != nil {
		t.Fatal(err)
	}
	if v, err := c.TTL(); err != nil {
		t.Fatal(err)
	} else if v != ttl {
		t.Fatalf("got %v; want %v", v, ttl)
	}
}
コード例 #18
0
ファイル: verify_test.go プロジェクト: rosrad/go-rep
func TestSystemVerify(t *testing.T) {
	if runtime.GOOS != "windows" {
		t.Skipf("skipping verify test using system APIs on %q", runtime.GOOS)
	}

	testVerify(t, true)
}
コード例 #19
0
func TestPacketConnUnicastSocketOptions(t *testing.T) {
	switch runtime.GOOS {
	case "nacl", "plan9":
		t.Skipf("not supported on %s", runtime.GOOS)
	}
	ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
	if ifi == nil {
		t.Skipf("not available on %s", runtime.GOOS)
	}

	m, ok := nettest.SupportsRawIPSocket()
	for _, tt := range packetConnUnicastSocketOptionTests {
		if tt.net == "ip4" && !ok {
			t.Log(m)
			continue
		}
		c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
		if err != nil {
			t.Fatal(err)
		}
		defer c.Close()

		testUnicastSocketOptions(t, ipv4.NewPacketConn(c))
	}
}
コード例 #20
0
ファイル: unicast_posix_test.go プロジェクト: kostyll/gccpy
// TestDualStackTCPListener tests both single and double listen
// to a test listener with various address families, differnet
// listening address and same port.
func TestDualStackTCPListener(t *testing.T) {
	switch runtime.GOOS {
	case "plan9":
		t.Skipf("skipping test on %q", runtime.GOOS)
	}
	if !supportsIPv6 {
		t.Skip("ipv6 is not supported")
	}

	for _, tt := range dualStackListenerTests {
		if tt.wildcard && (testing.Short() || !*testExternal) {
			continue
		}
		switch runtime.GOOS {
		case "openbsd":
			if tt.wildcard && differentWildcardAddr(tt.laddr1, tt.laddr2) {
				tt.xerr = nil
			}
		}
		l1, port := usableListenPort(t, tt.net1, tt.laddr1)
		laddr := tt.laddr1 + ":" + port
		checkFirstListener(t, tt.net1, laddr, l1)
		laddr = tt.laddr2 + ":" + port
		l2, err := Listen(tt.net2, laddr)
		checkDualStackSecondListener(t, tt.net2, laddr, tt.xerr, err, l2)
		l1.Close()
	}
}
コード例 #21
0
ファイル: dict_test.go プロジェクト: davidsoloman/beats
func getSize(t *testing.T, main string) int {
	size, err := testtext.CodeSize(fmt.Sprintf(body, main))
	if err != nil {
		t.Skipf("skipping link size test; binary size could not be determined: %v", err)
	}
	return size
}
コード例 #22
0
ファイル: unicast_posix_test.go プロジェクト: kostyll/gccpy
func TestWildWildcardListener(t *testing.T) {
	switch runtime.GOOS {
	case "plan9":
		t.Skipf("skipping test on %q", runtime.GOOS)
	}

	if testing.Short() || !*testExternal {
		t.Skip("skipping test to avoid external network")
	}

	defer func() {
		if recover() != nil {
			t.Fatalf("panicked")
		}
	}()

	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()
	}
}
コード例 #23
0
ファイル: icmp_test.go プロジェクト: anlaneg/socketplane
func TestICMPFilter(t *testing.T) {
	switch runtime.GOOS {
	case "nacl", "plan9", "solaris", "windows":
		t.Skipf("not supported on %s", runtime.GOOS)
	}

	var f ipv6.ICMPFilter
	for _, toggle := range []bool{false, true} {
		f.SetAll(toggle)
		for _, typ := range []ipv6.ICMPType{
			ipv6.ICMPTypeDestinationUnreachable,
			ipv6.ICMPTypeEchoReply,
			ipv6.ICMPTypeNeighborSolicitation,
			ipv6.ICMPTypeDuplicateAddressConfirmation,
		} {
			f.Accept(typ)
			if f.WillBlock(typ) {
				t.Errorf("ipv6.ICMPFilter.Set(%v, false) failed", typ)
			}
			f.Block(typ)
			if !f.WillBlock(typ) {
				t.Errorf("ipv6.ICMPFilter.Set(%v, true) failed", typ)
			}
		}
	}
}
コード例 #24
0
ファイル: unicast_posix_test.go プロジェクト: kostyll/gccpy
// TestUDPListener tests both single and double listen to a test
// listener with same address family, same listening address and
// same port.
func TestUDPListener(t *testing.T) {
	switch runtime.GOOS {
	case "plan9":
		t.Skipf("skipping test on %q", runtime.GOOS)
	}

	toudpnet := func(net string) string {
		switch net {
		case "tcp":
			return "udp"
		case "tcp4":
			return "udp4"
		case "tcp6":
			return "udp6"
		}
		return "<nil>"
	}

	for _, tt := range listenerTests {
		if tt.wildcard && (testing.Short() || !*testExternal) {
			continue
		}
		if tt.ipv6 && !supportsIPv6 {
			continue
		}
		tt.net = toudpnet(tt.net)
		l1, port := usableListenPacketPort(t, tt.net, tt.laddr)
		checkFirstListener(t, tt.net, tt.laddr+":"+port, l1)
		l2, err := ListenPacket(tt.net, tt.laddr+":"+port)
		checkSecondListener(t, tt.net, tt.laddr+":"+port, err, l2)
		l1.Close()
	}
}
コード例 #25
0
ファイル: os_test.go プロジェクト: duhaibo0404/go-1
func TestHostname(t *testing.T) {
	// There is no other way to fetch hostname on windows, but via winapi.
	// On Plan 9 it can be taken from #c/sysname as Hostname() does.
	switch runtime.GOOS {
	case "android", "plan9":
		t.Skipf("%s doesn't have /bin/hostname", runtime.GOOS)
	case "windows":
		testWindowsHostname(t)
		return
	}

	testenv.MustHaveExec(t)

	// Check internal Hostname() against the output of /bin/hostname.
	// Allow that the internal Hostname returns a Fully Qualified Domain Name
	// and the /bin/hostname only returns the first component
	hostname, err := Hostname()
	if err != nil {
		t.Fatalf("%v", err)
	}
	want := runBinHostname(t)
	if hostname != want {
		i := strings.Index(hostname, ".")
		if i < 0 || hostname[0:i] != want {
			t.Errorf("Hostname() = %q, want %q", hostname, want)
		}
	}
}
コード例 #26
0
ファイル: timeout_test.go プロジェクト: Mahdi89/riscv-go
func TestReadTimeout(t *testing.T) {
	t.Parallel()

	switch runtime.GOOS {
	case "plan9":
		t.Skipf("not supported on %s", runtime.GOOS)
	}

	handler := func(ls *localServer, ln Listener) {
		c, err := ln.Accept()
		if err != nil {
			t.Error(err)
			return
		}
		c.Write([]byte("READ TIMEOUT TEST"))
		defer c.Close()
	}
	ls, err := newLocalServer("tcp")
	if err != nil {
		t.Fatal(err)
	}
	defer ls.teardown()
	if err := ls.buildup(handler); err != nil {
		t.Fatal(err)
	}

	c, err := Dial(ls.Listener.Addr().Network(), ls.Listener.Addr().String())
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()

	for i, tt := range readTimeoutTests {
		if err := c.SetReadDeadline(time.Now().Add(tt.timeout)); err != nil {
			t.Fatalf("#%d: %v", i, err)
		}
		var b [1]byte
		for j, xerr := range tt.xerrs {
			for {
				n, err := c.Read(b[:])
				if xerr != nil {
					if perr := parseReadError(err); perr != nil {
						t.Errorf("#%d/%d: %v", i, j, perr)
					}
					if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
						t.Fatalf("#%d/%d: %v", i, j, err)
					}
				}
				if err == nil {
					time.Sleep(tt.timeout / 3)
					continue
				}
				if n != 0 {
					t.Fatalf("#%d/%d: read %d; want 0", i, j, n)
				}
				break
			}
		}
	}
}
コード例 #27
0
ファイル: os_test.go プロジェクト: duhaibo0404/go-1
func TestGetppid(t *testing.T) {
	if runtime.GOOS == "plan9" {
		// TODO: golang.org/issue/8206
		t.Skipf("skipping test on plan9; see issue 8206")
	}

	testenv.MustHaveExec(t)

	if Getenv("GO_WANT_HELPER_PROCESS") == "1" {
		fmt.Print(Getppid())
		Exit(0)
	}

	cmd := osexec.Command(Args[0], "-test.run=TestGetppid")
	cmd.Env = append(Environ(), "GO_WANT_HELPER_PROCESS=1")

	// verify that Getppid() from the forked process reports our process id
	output, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatalf("Failed to spawn child process: %v %q", err, string(output))
	}

	childPpid := string(output)
	ourPid := fmt.Sprintf("%d", Getpid())
	if childPpid != ourPid {
		t.Fatalf("Child process reports parent process id '%v', expected '%v'", childPpid, ourPid)
	}
}
コード例 #28
0
ファイル: map_test.go プロジェクト: davidsoloman/beats
// TestAlloc tests that some mapping methods should not cause any allocation.
func TestAlloc(t *testing.T) {
	dst := make([]byte, 256) // big enough to hold any result
	src := []byte(txtNonASCII)

	for i, f := range []func() Caser{
		func() Caser { return Upper(language.Und) },
		func() Caser { return Lower(language.Und) },
		func() Caser { return Title(language.Und) },
	} {
		var c Caser
		v := testing.AllocsPerRun(2, func() {
			c = f()
		})
		if v > 1 {
			// TODO: Right now only Upper has 1 allocation. Special-case Lower
			// and Title as well to have less allocations for the root locale.
			t.Skipf("%d:init: number of allocs was %f; want 0", i, v)
		}
		v = testing.AllocsPerRun(2, func() {
			c.Transform(dst, src, true)
		})
		if v > 0 {
			t.Errorf("%d:transform: number of allocs was %f; want 0", i, v)
		}
	}
}
コード例 #29
0
ファイル: exec_test.go プロジェクト: klueska/go-akaros
func TestCommandRelativeName(t *testing.T) {
	if runtime.GOOS == "darwin" && runtime.GOARCH == "arm" {
		t.Skip("skipping on darwin/arm")
	}

	// Run our own binary as a relative path
	// (e.g. "_test/exec.test") our parent directory.
	base := filepath.Base(os.Args[0]) // "exec.test"
	dir := filepath.Dir(os.Args[0])   // "/tmp/go-buildNNNN/os/exec/_test"
	if dir == "." {
		t.Skip("skipping; running test at root somehow")
	}
	parentDir := filepath.Dir(dir) // "/tmp/go-buildNNNN/os/exec"
	dirBase := filepath.Base(dir)  // "_test"
	if dirBase == "." {
		t.Skipf("skipping; unexpected shallow dir of %q", dir)
	}

	cmd := exec.Command(filepath.Join(dirBase, base), "-test.run=TestHelperProcess", "--", "echo", "foo")
	cmd.Dir = parentDir
	cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}

	out, err := cmd.Output()
	if err != nil {
		t.Errorf("echo: %v", err)
	}
	if g, e := string(out), "foo\n"; g != e {
		t.Errorf("echo: want %q, got %q", e, g)
	}
}
コード例 #30
0
ファイル: context_test.go プロジェクト: npchp110/text
func TestCaseProperties(t *testing.T) {
	if unicode.Version != UnicodeVersion {
		t.Skipf("UnicodeVersion=%s, but unicode.Version=%s", UnicodeVersion, unicode.Version)
	}
	assigned := rangetable.Assigned(UnicodeVersion)
	for r := rune(0); r <= lastRuneForTesting; r++ {
		if !unicode.In(r, assigned) || !unicode.In(unicode.SimpleFold(r), assigned) {
			continue
		}
		c := contextFromRune(r)
		if got, want := c.info.isCaseIgnorable(), propIgnore(r); got != want {
			t.Errorf("caseIgnorable(%U): got %v; want %v (%x)", r, got, want, c.info)
		}
		if got, want := c.info.isCased(), propCased(r); got != want {
			t.Errorf("cased(%U): got %v; want %v (%x)", r, got, want, c.info)
		}
		if got, want := c.caseType() == cUpper, propUpper(r); got != want {
			t.Errorf("upper(%U): got %v; want %v (%x)", r, got, want, c.info)
		}
		if got, want := c.caseType() == cLower, propLower(r); got != want {
			t.Errorf("lower(%U): got %v; want %v (%x)", r, got, want, c.info)
		}
		if got, want := c.info.isBreak(), hasBreakProp(r); got != want {
			t.Errorf("isBreak(%U): got %v; want %v (%x)", r, got, want, c.info)
		}
	}
	// TODO: get title case from unicode file.
}