2023-10-24 00:18:16 +00:00
|
|
|
package config
|
|
|
|
|
2024-02-25 01:45:26 +00:00
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
2023-10-24 00:18:16 +00:00
|
|
|
|
|
|
|
func TestLoadConfig(t *testing.T) {
|
|
|
|
conf := Load()
|
2024-02-25 01:45:26 +00:00
|
|
|
assert.Equal(t, "sqlite", conf.DBType)
|
2023-10-24 00:18:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetEnvDefault(t *testing.T) {
|
2024-02-25 01:45:26 +00:00
|
|
|
desiredValue := "def_val"
|
|
|
|
envDefault := getEnv("DEFAULT_TEST", desiredValue)
|
2023-10-24 00:18:16 +00:00
|
|
|
|
2024-02-25 01:45:26 +00:00
|
|
|
assert.Equal(t, desiredValue, envDefault)
|
2023-10-24 00:18:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTrimLowerString(t *testing.T) {
|
2024-02-25 01:45:26 +00:00
|
|
|
desiredValue := "trimtest"
|
|
|
|
outputValue := trimLowerString(" trimTest ")
|
|
|
|
|
|
|
|
assert.Equal(t, desiredValue, outputValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrettyCaller(t *testing.T) {
|
|
|
|
p, _, _, _ := runtime.Caller(0)
|
|
|
|
result := runtime.CallersFrames([]uintptr{p})
|
|
|
|
f, _ := result.Next()
|
|
|
|
functionName, fileName := prettyCaller(&f)
|
|
|
|
|
|
|
|
assert.Equal(t, "TestPrettyCaller", functionName, "should have current function name")
|
|
|
|
assert.Equal(t, "config/config_test.go@30", fileName, "should have current file path and line number")
|
2023-10-24 00:18:16 +00:00
|
|
|
}
|