101 lines
2.6 KiB
Go
101 lines
2.6 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDatabaseConfig_MigrateDSN_Cov(t *testing.T) {
|
|
d := DatabaseConfig{DSN: "postgres://user:pass@localhost:5432/db"}
|
|
assert.Equal(t, "postgres://user:pass@localhost:5432/db", d.MigrateDSN())
|
|
}
|
|
|
|
func TestDatabaseConfig_GetMigrationsPath_Default(t *testing.T) {
|
|
d := DatabaseConfig{}
|
|
assert.Equal(t, "migrations", d.GetMigrationsPath())
|
|
}
|
|
|
|
func TestDatabaseConfig_GetMigrationsPath_Custom(t *testing.T) {
|
|
d := DatabaseConfig{MigrationsPath: "/custom/path"}
|
|
assert.Equal(t, "/custom/path", d.GetMigrationsPath())
|
|
}
|
|
|
|
func TestJWTConfig_ExpiryDuration_Cov(t *testing.T) {
|
|
j := JWTConfig{ExpiryHours: 24}
|
|
assert.Equal(t, 24*time.Hour, j.ExpiryDuration())
|
|
}
|
|
|
|
func TestJWTConfig_ExpiryDuration_Cov_Zero(t *testing.T) {
|
|
j := JWTConfig{ExpiryHours: 0}
|
|
assert.Equal(t, time.Duration(0), j.ExpiryDuration())
|
|
}
|
|
|
|
func TestParseStatementTimeout_Empty(t *testing.T) {
|
|
d, err := ParseStatementTimeout("")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 14*time.Second, d)
|
|
}
|
|
|
|
func TestParseStatementTimeout_PlainSeconds(t *testing.T) {
|
|
d, err := ParseStatementTimeout("30")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 30*time.Second, d)
|
|
}
|
|
|
|
func TestParseStatementTimeout_Duration(t *testing.T) {
|
|
d, err := ParseStatementTimeout("500ms")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 500*time.Millisecond, d)
|
|
}
|
|
|
|
func TestParseStatementTimeout_Invalid(t *testing.T) {
|
|
_, err := ParseStatementTimeout("invalid")
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestParseDotEnvLine_Valid(t *testing.T) {
|
|
key, val, ok := parseDotEnvLine("KEY=value")
|
|
assert.True(t, ok)
|
|
assert.Equal(t, "KEY", key)
|
|
assert.Equal(t, "value", val)
|
|
}
|
|
|
|
func TestParseDotEnvLine_Quoted(t *testing.T) {
|
|
key, val, ok := parseDotEnvLine(`KEY="quoted value"`)
|
|
assert.True(t, ok)
|
|
assert.Equal(t, "KEY", key)
|
|
assert.Equal(t, "quoted value", val)
|
|
}
|
|
|
|
func TestParseDotEnvLine_SingleQuoted(t *testing.T) {
|
|
key, val, ok := parseDotEnvLine(`KEY='quoted value'`)
|
|
assert.True(t, ok)
|
|
assert.Equal(t, "KEY", key)
|
|
assert.Equal(t, "quoted value", val)
|
|
}
|
|
|
|
func TestParseDotEnvLine_Comment(t *testing.T) {
|
|
_, _, ok := parseDotEnvLine("# comment")
|
|
assert.False(t, ok)
|
|
}
|
|
|
|
func TestParseDotEnvLine_Empty(t *testing.T) {
|
|
_, _, ok := parseDotEnvLine("")
|
|
assert.False(t, ok)
|
|
}
|
|
|
|
func TestParseDotEnvLine_NoEquals(t *testing.T) {
|
|
_, _, ok := parseDotEnvLine("NOSEPARATOR")
|
|
assert.False(t, ok)
|
|
}
|
|
|
|
func TestParseDotEnvLine_WithSpaces(t *testing.T) {
|
|
key, val, ok := parseDotEnvLine(" KEY = value ")
|
|
assert.True(t, ok)
|
|
assert.Equal(t, "KEY", key)
|
|
assert.Equal(t, "value", val)
|
|
}
|