47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
|
|
package config
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestReadProjectConfig_Basic(t *testing.T) {
|
||
|
|
file, err := os.CreateTemp("", "projectconfig_*.json")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("failed to create temp file: %v", err)
|
||
|
|
}
|
||
|
|
defer os.Remove(file.Name())
|
||
|
|
|
||
|
|
jsonContent := `{
|
||
|
|
"log_format": "full",
|
||
|
|
"deployment_file": "pipeline.json",
|
||
|
|
"deployment_mode": "json",
|
||
|
|
"deployment_type": "development"
|
||
|
|
}`
|
||
|
|
file.WriteString(jsonContent)
|
||
|
|
file.Close()
|
||
|
|
|
||
|
|
pipelineFile, err := os.CreateTemp("", "pipeline_*.json")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("failed to create temp pipeline file: %v", err)
|
||
|
|
}
|
||
|
|
defer os.Remove(pipelineFile.Name())
|
||
|
|
pipelineFile.WriteString(`{}`) // minimal valid JSON
|
||
|
|
pipelineFile.Close()
|
||
|
|
|
||
|
|
pipelineFilePath := pipelineFile.Name()
|
||
|
|
config, err := ReadProjectConfig(file.Name(), &pipelineFilePath)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("ReadProjectConfig failed: %v", err)
|
||
|
|
}
|
||
|
|
if config.LogFormat != "full" {
|
||
|
|
t.Errorf("expected LogFormat 'full', got '%s'", config.LogFormat)
|
||
|
|
}
|
||
|
|
if config.DeploymentFile != pipelineFilePath {
|
||
|
|
t.Errorf("expected DeploymentFile '%s', got '%s'", pipelineFilePath, config.DeploymentFile)
|
||
|
|
}
|
||
|
|
if config.DeploymentMode != "json" {
|
||
|
|
t.Errorf("expected DeploymentMode 'json', got '%s'", config.DeploymentMode)
|
||
|
|
}
|
||
|
|
}
|