github.com/RevenueMonster/sqlike@v1.0.6/sql/dialect/mysql/connect_test.go (about)

     1  package mysql
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/RevenueMonster/sqlike/sqlike/options"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  // TestConnect :
    11  func TestConnect(t *testing.T) {
    12  	var (
    13  		ms  = MySQL{}
    14  		str string
    15  	)
    16  
    17  	str = ms.Connect(&options.ConnectOptions{
    18  		Username: "root",
    19  		Host:     "localhost",
    20  		Port:     "3306",
    21  	})
    22  	require.Equal(t, `root:@tcp(localhost:3306)/?parseTime=true&charset=utf8mb4&collation=utf8mb4_unicode_ci`, str)
    23  
    24  	uri := `root:@unix(localhost:3306)/?parseTime=true&charset=utf8mb4&collation=utf8mb4_unicode_ci`
    25  	opt := new(options.ConnectOptions)
    26  	str = ms.Connect(opt.ApplyURI(uri))
    27  	require.Equal(t, uri, str)
    28  	require.Panics(t, func() {
    29  		ms.Connect(nil)
    30  	})
    31  
    32  	require.Panics(t, func() {
    33  		opt := new(options.ConnectOptions)
    34  		ms.Connect(opt)
    35  	})
    36  }