mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-06-19 16:45:15 +03:00
feat: add tests
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
package config_yaml
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAgentConfig_GetLogLevel(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
cfg AgentConfig
|
||||||
|
wantLogLevel zerolog.Level
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "success",
|
||||||
|
cfg: AgentConfig{LogLevel: "DEBUG"},
|
||||||
|
wantLogLevel: zerolog.DebugLevel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "failed parse",
|
||||||
|
cfg: AgentConfig{LogLevel: "TEST"},
|
||||||
|
wantLogLevel: zerolog.InfoLevel,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
tt := tt
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
logLevel := tt.cfg.GetLogLevel()
|
||||||
|
|
||||||
|
if logLevel != tt.wantLogLevel {
|
||||||
|
t.Fatalf("expected %v, got: %v", tt.wantLogLevel, logLevel)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConfig_GetLogLevel(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
cfg Config
|
||||||
|
wantLogLevel zerolog.Level
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "success",
|
||||||
|
cfg: Config{LogLevel: "DEBUG"},
|
||||||
|
wantLogLevel: zerolog.DebugLevel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "failed parse",
|
||||||
|
cfg: Config{LogLevel: "TEST"},
|
||||||
|
wantLogLevel: zerolog.InfoLevel,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
tt := tt
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
logLevel := tt.cfg.GetLogLevel()
|
||||||
|
|
||||||
|
if logLevel != tt.wantLogLevel {
|
||||||
|
t.Fatalf("expected %v, got: %v", tt.wantLogLevel, logLevel)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfig_GetURLPostgres(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
cfg Config
|
||||||
|
wantURLPostgres string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "success",
|
||||||
|
cfg: Config{
|
||||||
|
DBHost: "TestHost",
|
||||||
|
DBName: "TestName",
|
||||||
|
DBPassword: "TestPassword",
|
||||||
|
DBPort: 1234,
|
||||||
|
DBUser: "TestUser",
|
||||||
|
},
|
||||||
|
wantURLPostgres: "postgres://TestUser:TestPassword@TestHost:1234/TestName?sslmode=disable",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
tt := tt
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
url := tt.cfg.GetURLPostgres()
|
||||||
|
|
||||||
|
if url != tt.wantURLPostgres {
|
||||||
|
t.Fatalf("expected %v, got: %v", tt.wantURLPostgres, url)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user