From c095fadc4503b988cdcbf6fd6b87ddb48caa9649 Mon Sep 17 00:00:00 2001 From: lorsan Date: Sat, 11 Apr 2026 14:48:53 +0300 Subject: [PATCH] feat: add tests --- .../utils/config_yaml/config_yaml_test.go | 41 ++++++++++ internal/shared/config/config_test.go | 76 +++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 internal/agent/utils/config_yaml/config_yaml_test.go create mode 100644 internal/shared/config/config_test.go diff --git a/internal/agent/utils/config_yaml/config_yaml_test.go b/internal/agent/utils/config_yaml/config_yaml_test.go new file mode 100644 index 0000000..f662117 --- /dev/null +++ b/internal/agent/utils/config_yaml/config_yaml_test.go @@ -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) + } + }) + } +} diff --git a/internal/shared/config/config_test.go b/internal/shared/config/config_test.go new file mode 100644 index 0000000..1ad1bc1 --- /dev/null +++ b/internal/shared/config/config_test.go @@ -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) + } + }) + } +}