package config_test import ( "testing" "git.ar21.de/yolokube/grafana-backuper/internal/config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestConfig_Validate_MissingFields(t *testing.T) { cfg := config.Config{} errs := cfg.Validate() assert.Len(t, errs, 6) // Expecting 6 errors since all required fields are missing require.ErrorIs(t, errs[0], config.ErrInvalidGrafanaURL) require.ErrorIs(t, errs[1], config.ErrInvalidAuthToken) require.ErrorIs(t, errs[2], config.ErrInvalidRepoURL) require.ErrorIs(t, errs[3], config.ErrInvalidGitUser) require.ErrorIs(t, errs[4], config.ErrInvalidGitPass) require.ErrorIs(t, errs[5], config.ErrInvalidBranchName) } func TestConfig_Validate_AllFieldsPresent(t *testing.T) { cfg := config.Config{ GrafanaURL: "http://grafana.example.com", GrafanaToken: "sometoken", GitRepo: "https://github.com/user/repo", GitUser: "username", GitPass: "password", GitBranch: "main", } errs := cfg.Validate() assert.Empty(t, errs) // No errors should be returned when all fields are valid } func TestConfig_Validate_PartiallyPopulated(t *testing.T) { cfg := config.Config{ GrafanaURL: "http://grafana.example.com", GitRepo: "https://github.com/user/repo", GitUser: "username", } errs := cfg.Validate() assert.Len(t, errs, 3) // Expecting 3 errors for missing GrafanaToken, GitPass, and GitBranch require.ErrorIs(t, errs[0], config.ErrInvalidGrafanaURL) require.ErrorIs(t, errs[1], config.ErrInvalidGitPass) require.ErrorIs(t, errs[2], config.ErrInvalidBranchName) }