test(config,git,logger): add some test functions
This commit is contained in:
parent
316e5de757
commit
1356128a7b
16 changed files with 387 additions and 25 deletions
40
internal/config/config_test.go
Normal file
40
internal/config/config_test.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue