aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-01-06 11:30:47 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2024-01-06 11:30:47 -0500
commit89148cfc25722ac6fb6ef609449566039c31285a (patch)
treed129c2d878c2925abcae37ea69d4a788d0dc865b /internal
parentRename job (diff)
downloadcli-89148cfc25722ac6fb6ef609449566039c31285a.zip
Tweak a few comments
Diffstat (limited to 'internal')
-rw-r--r--internal/storage/storage.go11
-rw-r--r--internal/storage/storage_test.go22
2 files changed, 15 insertions, 18 deletions
diff --git a/internal/storage/storage.go b/internal/storage/storage.go
index cd6e514..25db283 100644
--- a/internal/storage/storage.go
+++ b/internal/storage/storage.go
@@ -8,8 +8,10 @@ import (
_ "github.com/lib/pq"
)
-// DBConnect to the database using the driver and connection
-// information.
+// DBConnect establishes a connection to the database using the driver
+// and connection information.
+//
+// Note that only "postgres" is supported as the driver right now.
func DBConnect(driver string, connectionInfo string) (*sql.DB, error) {
db, err := sql.Open(driver, connectionInfo)
if err != nil {
@@ -29,9 +31,8 @@ func DBConnect(driver string, connectionInfo string) (*sql.DB, error) {
}
// DBConnectionString generates a properly formatted connection
-// string to be passed to a database management system to initiate
-// a connection. It uses the passed in configuration values to create
-// the string. Note that sslmode is always disabled.
+// string that can be used to establish a database connection.
+// Note that it always creates a connection string with sslmode disabled.
func DBConnectionString(cfg *configloader.ConnectionConfig) string {
return fmt.Sprintf(
"host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
diff --git a/internal/storage/storage_test.go b/internal/storage/storage_test.go
index 53f7b49..3b36a34 100644
--- a/internal/storage/storage_test.go
+++ b/internal/storage/storage_test.go
@@ -51,24 +51,20 @@ func TestDBConnectUnsupportedDriver(t *testing.T) {
}
func TestDBConnectionString(t *testing.T) {
- cfg := configloader.Config{
- MigrationsDir: "",
- Connection: configloader.ConnectionConfig{
- Driver: "postgres",
- Host: "db1",
- Port: 5432,
- User: "testuser",
- Password: "supersecretpassword",
- DBName: "testdb",
- },
+ 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.Connection.Host, cfg.Connection.Port, cfg.Connection.User,
- cfg.Connection.Password, cfg.Connection.DBName,
+ cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.DBName,
)
- cs := storage.DBConnectionString(&cfg.Connection)
+ cs := storage.DBConnectionString(&cfg)
if cs != expectedConnectionString {
t.Fatalf("Expected %s, got %s", expectedConnectionString, cs)