github.com/phuslu/log@v1.0.100/goid_test.go (about)

     1  package log
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  	"strings"
     7  	"testing"
     8  )
     9  
    10  func TestGoid(t *testing.T) {
    11  	var data [256]byte
    12  
    13  	id := Goid()
    14  	a := fmt.Sprintf("goroutine %d ", id)
    15  	b := data[:]
    16  	b = b[:runtime.Stack(b, false)]
    17  
    18  	if !strings.HasPrefix(string(b), a) {
    19  		t.Errorf("runtime.Stack return %s, does contains goid %d", b, id)
    20  	}
    21  }