Skip to content

Commit

Permalink
test(client): test the client using the way to build the conn string
Browse files Browse the repository at this point in the history
  • Loading branch information
danvergara committed Apr 22, 2021
1 parent 834a34e commit a953301
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import (
"os"
"testing"

// mysql driver.
_ "github.com/go-sql-driver/mysql"
// postgres driver.
_ "github.com/lib/pq"

"github.com/danvergara/dblab/pkg/command"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -34,7 +39,7 @@ func generateURL(driver string) string {
case "postgres":
return fmt.Sprintf("%s://%s:%s@%s:%s/%s?sslmode=mode", driver, user, password, host, port, name)
case "mysql":
return fmt.Sprintf("%s://%s:%s@tcp(%s:%s)/%s?sslmode=mode", driver, user, password, host, port, name)
return fmt.Sprintf("%s://%s:%s@tcp(%s:%s)/%s", driver, user, password, host, port, name)
default:
return ""
}
Expand All @@ -53,10 +58,57 @@ func TestNewClientByURL(t *testing.T) {
}

c, err := New(opts)
if err != nil {
t.Error(err)
}

assert.NotNil(t, c)
}

func TestNewClientByUserData(t *testing.T) {
if testing.Short() {
t.Skip("skipping short mode")
}

opts := command.Options{
Driver: driver,
User: user,
Pass: password,
Host: host,
Port: port,
DBName: name,
}

c, err := New(opts)
if err != nil {
t.Error(err)
}

assert.NotNil(t, c)
}

func TestNewClientPing(t *testing.T) {
if testing.Short() {
t.Skip("skipping short mode")
}

opts := command.Options{
Driver: driver,
User: user,
Pass: password,
Host: host,
Port: port,
DBName: name,
}

c, err := New(opts)
if err != nil {
t.Error(err)
}

assert.NotNil(t, c)

if err := c.DB().Ping(); err != nil {
t.Error(err)
}
}

0 comments on commit a953301

Please sign in to comment.