smartconfig/cli_missing_env_test.go
sneak 8a38afba5e passes tests, has cli filter now.
* still has not been *really* tested yet
2025-07-20 15:29:06 +02:00

32 lines
823 B
Go

package smartconfig
import (
"os"
"strings"
"testing"
)
func TestCLIMissingEnvInterpolation(t *testing.T) {
// Don't set TEST_APP_NAME - it should cause an error
// Set TEST_PORT to verify partial interpolation works
_ = os.Setenv("TEST_PORT", "3000")
defer func() {
_ = os.Unsetenv("TEST_PORT")
}()
// Test YAML content with missing env var
yamlContent := `name: ${ENV:TEST_APP_NAME}
port: ${ENV:TEST_PORT}
host: localhost`
// Create config from reader - should fail due to missing TEST_APP_NAME
reader := strings.NewReader(yamlContent)
_, err := NewFromReader(reader)
if err == nil {
t.Fatal("Expected error when environment variable is missing, but got none")
}
if !strings.Contains(err.Error(), "TEST_APP_NAME") {
t.Errorf("Expected error to mention missing TEST_APP_NAME, got: %v", err)
}
}