aboutsummaryrefslogtreecommitdiffstats
path: root/internal/storage/storage_test.go
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-01-06 16:23:02 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2024-01-06 16:23:02 -0500
commit263ce3e4b368a50efee1a53af11a76a12af0a119 (patch)
tree8917754f3b43830604f6ad4c7115934ed633f1d8 /internal/storage/storage_test.go
parentFix syntax (diff)
downloadcli-263ce3e4b368a50efee1a53af11a76a12af0a119.zip
Break up migration repo into fs and db with a service
Diffstat (limited to 'internal/storage/storage_test.go')
-rw-r--r--internal/storage/storage_test.go72
1 files changed, 0 insertions, 72 deletions
diff --git a/internal/storage/storage_test.go b/internal/storage/storage_test.go
deleted file mode 100644
index 3b36a34..0000000
--- a/internal/storage/storage_test.go
+++ /dev/null
@@ -1,72 +0,0 @@
-package storage_test
-
-import (
- "fmt"
- "strings"
- "testing"
-
- "github.com/eugenetriguba/bolt/internal/configloader"
- "github.com/eugenetriguba/bolt/internal/dbtest"
- "github.com/eugenetriguba/bolt/internal/storage"
-)
-
-func TestDBConnectWithPostgres(t *testing.T) {
- cfg, err := dbtest.NewTestConnectionConfig("postgres")
- if err != nil {
- t.Fatal(err)
- }
-
- conn, err := storage.DBConnect(cfg.Driver, storage.DBConnectionString(cfg))
- if err != nil {
- t.Fatalf("could not connect to postgres db using %s: %s",
- storage.DBConnectionString(cfg),
- err,
- )
- }
- defer conn.Close()
-
- _, err = conn.Exec("SELECT 1;")
- if err != nil {
- t.Fatalf("could not execute query against postgres db: %s", err)
- }
-}
-
-func TestDBConnectMalformedConnectionString(t *testing.T) {
- _, err := storage.DBConnect("postgres", "pizza=123")
- if err == nil || (err != nil && !strings.Contains(err.Error(), "connection refused")) {
- t.Fatalf("expected connection error, got %s", err)
- }
-}
-
-func TestDBConnectUnsupportedDriver(t *testing.T) {
- cfg, err := dbtest.NewTestConnectionConfig("redis")
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = storage.DBConnect(cfg.Driver, storage.DBConnectionString(cfg))
- if err == nil || (err != nil && !strings.Contains(err.Error(), `unknown driver "redis"`)) {
- t.Fatalf("expected bad driver, got %s", err)
- }
-}
-
-func TestDBConnectionString(t *testing.T) {
- cfg := configloader.ConnectionConfig{
- Driver: "postgres",
- Host: "db1",
- Port: 5432,
- User: "testuser",
- Password: "supersecretpassword",
- DBName: "testdb",
- }
- expectedConnectionString := fmt.Sprintf(
- "host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
- cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.DBName,
- )
-
- cs := storage.DBConnectionString(&cfg)
-
- if cs != expectedConnectionString {
- t.Fatalf("Expected %s, got %s", expectedConnectionString, cs)
- }
-}