github.com/nsqio/nsq@v1.3.0/internal/util/util_test.go (about)

     1  package util
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/nsqio/nsq/internal/test"
     7  )
     8  
     9  func BenchmarkUniqRands5of5(b *testing.B) {
    10  	for i := 0; i < b.N; i++ {
    11  		UniqRands(5, 5)
    12  	}
    13  }
    14  func BenchmarkUniqRands20of20(b *testing.B) {
    15  	for i := 0; i < b.N; i++ {
    16  		UniqRands(20, 20)
    17  	}
    18  }
    19  
    20  func BenchmarkUniqRands20of50(b *testing.B) {
    21  	for i := 0; i < b.N; i++ {
    22  		UniqRands(20, 50)
    23  	}
    24  }
    25  
    26  func TestUniqRands(t *testing.T) {
    27  	var x []int
    28  	x = UniqRands(3, 10)
    29  	test.Equal(t, 3, len(x))
    30  
    31  	x = UniqRands(10, 5)
    32  	test.Equal(t, 5, len(x))
    33  
    34  	x = UniqRands(10, 20)
    35  	test.Equal(t, 10, len(x))
    36  }
    37  
    38  func TestTypeOfAddr(t *testing.T) {
    39  	var x string
    40  	x = TypeOfAddr("127.0.0.1:80")
    41  	test.Equal(t, "tcp", x)
    42  
    43  	x = TypeOfAddr("test:80")
    44  	test.Equal(t, "tcp", x)
    45  
    46  	x = TypeOfAddr("/var/run/nsqd.sock")
    47  	test.Equal(t, "unix", x)
    48  
    49  	x = TypeOfAddr("[::1%lo0]:80")
    50  	test.Equal(t, "tcp", x)
    51  }