chore: Remove unused function
This commit is contained in:
parent
b7e3877b68
commit
de28bdbb0b
@ -3,12 +3,8 @@ package test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models"
|
|
||||||
migrate "github.com/rubenv/sql-migrate"
|
migrate "github.com/rubenv/sql-migrate"
|
||||||
postgrescontainer "github.com/testcontainers/testcontainers-go/modules/postgres"
|
postgrescontainer "github.com/testcontainers/testcontainers-go/modules/postgres"
|
||||||
"gorm.io/driver/postgres"
|
"gorm.io/driver/postgres"
|
||||||
@ -84,41 +80,3 @@ func getGormDB(connectionString string) (*gorm.DB, error) {
|
|||||||
TranslateError: true,
|
TranslateError: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func DatabaseModesFromConnectionString(ctx context.Context, pgContainer *postgrescontainer.PostgresContainer) (*models.DatabaseConfig, error) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
connectionString, err := pgContainer.ConnectionString(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
connectionStringUrl, err := url.Parse(connectionString)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
split := strings.Split(connectionStringUrl.Host, ":")
|
|
||||||
host := split[0]
|
|
||||||
|
|
||||||
port, err := strconv.Atoi(split[1])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
database := strings.TrimPrefix(connectionStringUrl.Path, "/")
|
|
||||||
|
|
||||||
username := connectionStringUrl.User.Username()
|
|
||||||
password, _ := connectionStringUrl.User.Password()
|
|
||||||
|
|
||||||
return &models.DatabaseConfig{
|
|
||||||
Endpoint: host,
|
|
||||||
Username: username,
|
|
||||||
Password: password,
|
|
||||||
Database: database,
|
|
||||||
Port: port,
|
|
||||||
SSL: false,
|
|
||||||
Timezone: "Europe/Berlin",
|
|
||||||
Debug: true,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user