refactor: switch config format from YAML to TOML
- Replace gopkg.in/yaml.v3 with github.com/BurntSushi/toml - Update struct tags from yaml to toml - Update config tests to use TOML syntax - Add testdata/config.toml, update Helm configmap template
This commit is contained in:
@@ -7,20 +7,22 @@ import (
|
||||
)
|
||||
|
||||
func TestLoad_MissingFile(t *testing.T) {
|
||||
_, err := Load("/nonexistent/config.yaml")
|
||||
_, err := Load("/nonexistent/config.toml")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for missing file")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoad_MissingGitToken(t *testing.T) {
|
||||
cfg := `server:
|
||||
addr: ":8080"
|
||||
git:
|
||||
type: gitea
|
||||
base_url: "https://git.example.com"
|
||||
cluster:
|
||||
namespace: proto-gen`
|
||||
cfg := `[server]
|
||||
addr = ":8080"
|
||||
|
||||
[git]
|
||||
type = "gitea"
|
||||
base_url = "https://git.example.com"
|
||||
|
||||
[cluster]
|
||||
namespace = "proto-gen"`
|
||||
path := writeTempConfig(t, cfg)
|
||||
os.Setenv("GIT_TOKEN", "")
|
||||
_, err := Load(path)
|
||||
@@ -33,19 +35,22 @@ func TestLoad_ValidConfig(t *testing.T) {
|
||||
os.Setenv("GIT_TOKEN", "test-token")
|
||||
defer os.Unsetenv("GIT_TOKEN")
|
||||
|
||||
cfg := `server:
|
||||
addr: ":9090"
|
||||
git:
|
||||
type: gitea
|
||||
base_url: "https://git.example.com"
|
||||
token: ${GIT_TOKEN}
|
||||
cluster:
|
||||
namespace: proto-gen
|
||||
job_timeout: 300
|
||||
max_concurrent: 3
|
||||
plugins:
|
||||
- language: go
|
||||
image: "proto-gen-go:v1.0"`
|
||||
cfg := `[server]
|
||||
addr = ":9090"
|
||||
|
||||
[git]
|
||||
type = "gitea"
|
||||
base_url = "https://git.example.com"
|
||||
token = "${GIT_TOKEN}"
|
||||
|
||||
[cluster]
|
||||
namespace = "proto-gen"
|
||||
job_timeout = 300
|
||||
max_concurrent = 3
|
||||
|
||||
[[plugins]]
|
||||
language = "go"
|
||||
image = "proto-gen-go:v1.0"`
|
||||
path := writeTempConfig(t, cfg)
|
||||
|
||||
got, err := Load(path)
|
||||
@@ -73,12 +78,13 @@ func TestLoad_DefaultValues(t *testing.T) {
|
||||
os.Setenv("GIT_TOKEN", "test-token")
|
||||
defer os.Unsetenv("GIT_TOKEN")
|
||||
|
||||
cfg := `git:
|
||||
type: gitea
|
||||
base_url: "https://git.example.com"
|
||||
token: ${GIT_TOKEN}
|
||||
cluster:
|
||||
namespace: proto-gen`
|
||||
cfg := `[git]
|
||||
type = "gitea"
|
||||
base_url = "https://git.example.com"
|
||||
token = "${GIT_TOKEN}"
|
||||
|
||||
[cluster]
|
||||
namespace = "proto-gen"`
|
||||
path := writeTempConfig(t, cfg)
|
||||
|
||||
got, err := Load(path)
|
||||
@@ -119,7 +125,7 @@ func TestGetPluginByLanguage(t *testing.T) {
|
||||
func writeTempConfig(t *testing.T, content string) string {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "config.yaml")
|
||||
path := filepath.Join(dir, "config.toml")
|
||||
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
|
||||
t.Fatalf("writing temp config: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user