Skip to content

Commit

Permalink
/modules/dolt/examples_test.go: remove panics, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeegoddd committed Feb 6, 2024
1 parent c1fa127 commit 09c4f55
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions modules/dolt/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"log"
"path/filepath"

"github.com/testcontainers/testcontainers-go"
Expand All @@ -23,20 +24,20 @@ func ExampleRunContainer() {
dolt.WithScripts(filepath.Join("testdata", "schema.sql")),
)
if err != nil {
panic(err)
log.Fatalf("failed to run dolt container: %s", err) // nolint:gocritic
}

// Clean up the container
defer func() {
if err := doltContainer.Terminate(ctx); err != nil {
panic(err)
log.Fatalf("failed to terminate dolt container: %s", err) // nolint:gocritic
}
}()
// }

state, err := doltContainer.State(ctx)
if err != nil {
panic(err)
log.Fatalf("failed to get container state: %s", err) // nolint:gocritic
}

fmt.Println(state.Running)
Expand All @@ -57,36 +58,36 @@ func ExampleRunContainer_connect() {
dolt.WithScripts(filepath.Join("testdata", "schema.sql")),
)
if err != nil {
panic(err)
log.Fatalf("failed to run dolt container: %s", err) // nolint:gocritic
}

defer func() {
if err := doltContainer.Terminate(ctx); err != nil {
panic(err)
log.Fatalf("failed to terminate dolt container: %s", err) // nolint:gocritic
}
}()

connectionString, _ := doltContainer.ConnectionString(ctx)

db, err := sql.Open("mysql", connectionString)
if err != nil {
panic(err)
log.Fatalf("failed to open database connection: %s", err) // nolint:gocritic
}
defer db.Close()

if err = db.Ping(); err != nil {
panic(err)
log.Fatalf("failed to ping database: %s", err) // nolint:gocritic
}
stmt, err := db.Prepare("SELECT dolt_version();")
if err != nil {
panic(err)
log.Fatalf("failed to prepate sql statement: %s", err) // nolint:gocritic
}
defer stmt.Close()
row := stmt.QueryRow()
version := ""
err = row.Scan(&version)
if err != nil {
panic(err)
log.Fatalf("failed to scan row: %s", err) // nolint:gocritic
}

fmt.Println(version)
Expand Down

0 comments on commit 09c4f55

Please sign in to comment.