grafana-backuper/internal/config/config_test.go

40 lines
1 KiB
Go

package config_test
import (
"testing"
"git.ar21.de/yolokube/grafana-backuper/internal/config"
"github.com/stretchr/testify/assert"
)
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
}
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
}