github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/p2p/simulations/adapters/ws_test.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  package adapters
    10  
    11  import (
    12  	"bytes"
    13  	"testing"
    14  	"time"
    15  )
    16  
    17  func TestFindWSAddr(t *testing.T) {
    18  line := `t=2018-05-02T19:00:45+0200 lvl=info msg="WebSocket endpoint opened"  node.id=26c65a606d1125a44695bc08573190d047152b6b9a776ccbbe593e90f91444d9c1ebdadac6a775ad9fdd0923468a1d698ed3a842c1fb89c1bc0f9d4801f8c39c url=ws://127.0.0.1:59975`
    19  	buf := bytes.NewBufferString(line)
    20  	got, err := findWSAddr(buf, 10*time.Second)
    21  	if err != nil {
    22  		t.Fatalf("Failed to find addr: %v", err)
    23  	}
    24  expected := `ws://127.0.0.1:59975`
    25  
    26  	if got != expected {
    27  		t.Fatalf("Expected to get '%s', but got '%s'", expected, got)
    28  	}
    29  }