github.com/anycable/anycable-go@v1.5.1/rpc/config_test.go (about)

     1  package rpc
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestConfig_Impl(t *testing.T) {
    10  	c := NewConfig()
    11  
    12  	c.Implementation = "http"
    13  	assert.Equal(t, "http", c.Impl())
    14  
    15  	c.Implementation = "trpc"
    16  	assert.Equal(t, "trpc", c.Impl())
    17  
    18  	c.Implementation = ""
    19  	assert.Equal(t, "grpc", c.Impl())
    20  
    21  	c.Host = "http://localhost:8080/anycable"
    22  	assert.Equal(t, "http", c.Impl())
    23  
    24  	c.Host = "https://localhost:8080/anycable"
    25  	assert.Equal(t, "http", c.Impl())
    26  
    27  	c.Host = "grpc://localhost:50051/anycable"
    28  	assert.Equal(t, "grpc", c.Impl())
    29  
    30  	c.Host = "dns:///rpc:50051"
    31  	assert.Equal(t, "grpc", c.Impl())
    32  
    33  	c.Host = "localhost:50051/anycable"
    34  	assert.Equal(t, "grpc", c.Impl())
    35  
    36  	c.Host = "127.0.0.1:50051/anycable"
    37  	assert.Equal(t, "grpc", c.Impl())
    38  
    39  	c.Host = "invalid://:+"
    40  	assert.Equal(t, "<invalid RPC host: invalid://:+>", c.Impl())
    41  }