Skip to content

Commit

Permalink
refactor(#6): Applied review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightapes committed Jun 29, 2021
1 parent 53c467d commit 94a7654
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 56 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This library uses the standard Golang [SQL driver interface](https://golang.org/

### Create Connection

#### With exasol dsn
#### With Exasol DSN

```go
package main
Expand All @@ -20,12 +20,12 @@ import (
)

func main() {
exasol, err := sql.Open("exasol", "exa:<host>:<port>;user=<username>;password=<password>")
database, err := sql.Open("exasol", "exa:<host>:<port>;user=<username>;password=<password>")
...
}
```

#### With exasol config
#### With Exasol Config

```go
package main
Expand All @@ -37,7 +37,7 @@ import (
)

func main() {
db, err := sql.Open("exasol", exasol.NewConfig("<username>", "<password>").Port(<port>).Host("<host>").String())
database, err := sql.Open("exasol", exasol.NewConfig("<username>", "<password>").Port(<port>).Host("<host>").String())
...
}
```
Expand Down Expand Up @@ -77,7 +77,7 @@ rows, err := preparedStatement.Query("Bob")
To control a transaction state manually, you would need to disable autocommit (enabled by default):

```go
exasol, err := sql.Open("exasol", "exa:<host>:<port>;user=<username>;password=<password>;autocommit=0")
database, err := sql.Open("exasol", "exa:<host>:<port>;user=<username>;password=<password>;autocommit=0")
```

After that you can begin a transaction:
Expand Down
15 changes: 9 additions & 6 deletions examples/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@ import (
_ "github.com/exasol/exasol-driver-go"
)

func main2() {
func main() {

fmt.Printf("Drivers=%#v\n", sql.Drivers())
db, err := sql.Open("exasol", "exa:localhost:8563;user=sys;password=<password>")
database, err := sql.Open("exasol", "exa:localhost:8563;user=sys;password=<password>")
onError(err)
defer database.Close()

err = db.Ping()
err = database.Ping()
onError(err)

rows, err := db.Query("SELECT * FROM t")
rows, err := database.Query("SELECT * FROM t")
onError(err)
defer rows.Close()

printColumns(rows)
printRows(rows)

result, err := db.Exec(`
result, err := database.Exec(`
INSERT INTO t
(Name, AValue)
VALUES('MyName', '12');`)
onError(err)
log.Println(result.RowsAffected())
db.Close()

}
56 changes: 11 additions & 45 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,58 +24,48 @@ type IntegrationTestSuite struct {
}

func TestIntegrationSuite(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
suite.Run(t, new(IntegrationTestSuite))
}

func (suite *IntegrationTestSuite) SetupSuite() {
if testing.Short() {
return
}
suite.ctx = getContext()
suite.exasolContainer = runExasolContainer(suite.ctx)
suite.port = getExasolPort(suite.exasolContainer, suite.ctx)
}

func (suite *IntegrationTestSuite) TestConnect() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}

db, _ := sql.Open("exasol", fmt.Sprintf("exa:localhost:%d;user=sys;password=exasol;encryption=0", suite.port))
rows, _ := db.Query("SELECT 2 FROM DUAL")
columns, _ := rows.Columns()
suite.Equal("2", columns[0])
}

func (suite *IntegrationTestSuite) TestConnectWithWrongPort() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}

exasol, _ := sql.Open("exasol", "exa:localhost:1234;user=sys;password=exasol")
err := exasol.Ping()
suite.Error(err)
suite.Contains(err.Error(), "connect: connection refuse")
}

func (suite *IntegrationTestSuite) TestConnectWithWrongUsername() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}

exasol, _ := sql.Open("exasol", exasol.NewConfig("wronguser", "exasol").Insecure(true).Port(suite.port).String())
suite.EqualError(exasol.Ping(), "[08004] Connection exception - authentication failed.")
}

func (suite *IntegrationTestSuite) TestConnectWithWrongPassword() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}

exasol, _ := sql.Open("exasol", exasol.NewConfig("sys", "wrongpassword").Insecure(true).Port(suite.port).String())
suite.EqualError(exasol.Ping(), "[08004] Connection exception - authentication failed.")
}

func (suite *IntegrationTestSuite) TestExecAndQuery() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}

exasol, _ := sql.Open("exasol", exasol.NewConfig("sys", "exasol").Insecure(true).Port(suite.port).String())
schemaName := "TEST_SCHEMA_1"
_, _ = exasol.Exec("CREATE SCHEMA " + schemaName)
Expand All @@ -86,19 +76,15 @@ func (suite *IntegrationTestSuite) TestExecAndQuery() {
}

func (suite *IntegrationTestSuite) TestExecuteWithError() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}

exasol, _ := sql.Open("exasol", exasol.NewConfig("sys", "exasol").Insecure(true).Port(suite.port).String())
_, err := exasol.Exec("CREATE SCHEMAA TEST_SCHEMA")
suite.Error(err)
suite.True(strings.Contains(err.Error(), "syntax error"))
}

func (suite *IntegrationTestSuite) TestQueryWithError() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}

exasol, _ := sql.Open("exasol", exasol.NewConfig("sys", "exasol").Insecure(true).Port(suite.port).String())
schemaName := "TEST_SCHEMA_2"
_, _ = exasol.Exec("CREATE SCHEMA " + schemaName)
Expand All @@ -108,9 +94,7 @@ func (suite *IntegrationTestSuite) TestQueryWithError() {
}

func (suite *IntegrationTestSuite) TestPreparedStatement() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}

exasol, _ := sql.Open("exasol", exasol.NewConfig("sys", "exasol").Insecure(true).Port(suite.port).String())
schemaName := "TEST_SCHEMA_3"
_, _ = exasol.Exec("CREATE SCHEMA " + schemaName)
Expand All @@ -123,9 +107,6 @@ func (suite *IntegrationTestSuite) TestPreparedStatement() {
}

func (suite *IntegrationTestSuite) TestBeginAndCommit() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}
exasol, _ := sql.Open("exasol", exasol.NewConfig("sys", "exasol").Insecure(true).Autocommit(false).Port(suite.port).String())
schemaName := "TEST_SCHEMA_4"
transaction, _ := exasol.Begin()
Expand All @@ -138,9 +119,6 @@ func (suite *IntegrationTestSuite) TestBeginAndCommit() {
}

func (suite *IntegrationTestSuite) TestBeginAndRollback() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}
exasol, _ := sql.Open("exasol", exasol.NewConfig("sys", "exasol").Insecure(true).Autocommit(false).Port(suite.port).String())
schemaName := "TEST_SCHEMA_5"
transaction, _ := exasol.Begin()
Expand All @@ -154,19 +132,13 @@ func (suite *IntegrationTestSuite) TestBeginAndRollback() {
}

func (suite *IntegrationTestSuite) TestPingWithContext() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}
exasol, _ := sql.Open("exasol", exasol.NewConfig("sys", "exasol").Insecure(true).Port(suite.port).String())
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
suite.NoError(exasol.PingContext(ctx))
cancel()
}

func (suite *IntegrationTestSuite) TestExecuteAndQueryWithContext() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}
exasol, _ := sql.Open("exasol", exasol.NewConfig("sys", "exasol").Insecure(true).Port(suite.port).String())
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
schemaName := "TEST_SCHEMA_6"
Expand All @@ -179,9 +151,6 @@ func (suite *IntegrationTestSuite) TestExecuteAndQueryWithContext() {
}

func (suite *IntegrationTestSuite) TestBeginWithCancelledContext() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}
exasol, _ := sql.Open("exasol", exasol.NewConfig("sys", "exasol").Insecure(true).Port(suite.port).Autocommit(false).String())
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
schemaName := "TEST_SCHEMA_7"
Expand All @@ -200,9 +169,6 @@ func (suite *IntegrationTestSuite) assertSingleValueResult(rows *sql.Rows, expec
}

func (suite *IntegrationTestSuite) TearDownSuite() {
if testing.Short() {
return
}
err := suite.exasolContainer.Terminate(suite.ctx)
onError(err)
}
Expand Down

0 comments on commit 94a7654

Please sign in to comment.