github.com/blend/go-sdk@v1.20220411.3/grpcutil/create_listener_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package grpcutil
     9  
    10  import (
    11  	"fmt"
    12  	"os"
    13  	"path/filepath"
    14  	"testing"
    15  
    16  	"github.com/blend/go-sdk/assert"
    17  	"github.com/blend/go-sdk/uuid"
    18  )
    19  
    20  func TestListener(t *testing.T) {
    21  	assert := assert.New(t)
    22  
    23  	tcpln, err := CreateListener("127.0.0.1:")
    24  	assert.Nil(err)
    25  	defer func() { _ = tcpln.Close() }()
    26  	assert.Equal("tcp", tcpln.Addr().Network())
    27  	assert.Contains(tcpln.Addr().String(), "127.0.0.1:")
    28  
    29  	socketDir := os.TempDir()
    30  	socketPath := filepath.Join(socketDir, uuid.V4().String())
    31  	socketAddress := fmt.Sprintf("unix://" + socketPath)
    32  	unixln, err := CreateListener(socketAddress)
    33  	assert.Nil(err)
    34  	defer func() { _ = unixln.Close() }()
    35  	assert.Equal("unix", unixln.Addr().Network())
    36  	assert.Equal(socketPath, unixln.Addr().String())
    37  }