forked from baron/baron-sso
레포 업데이트
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"baron-sso-backend/internal/logger"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
@@ -10,7 +11,7 @@ func IsProductionEnv() bool {
|
||||
if env == "" {
|
||||
env = strings.ToLower(os.Getenv("GO_ENV"))
|
||||
}
|
||||
return env == "prod" || env == "production"
|
||||
return logger.IsProductionLikeEnv(env)
|
||||
}
|
||||
|
||||
func IsDryRunAllowed() bool {
|
||||
|
||||
43
backend/internal/service/dry_run_service_test.go
Normal file
43
backend/internal/service/dry_run_service_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsProductionEnv_StageIsProductionLike(t *testing.T) {
|
||||
t.Setenv("APP_ENV", "stage")
|
||||
t.Setenv("GO_ENV", "")
|
||||
|
||||
if !IsProductionEnv() {
|
||||
t.Fatalf("expected stage to be treated as production-like")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsDryRunAllowed_DisabledInStage(t *testing.T) {
|
||||
t.Setenv("APP_ENV", "stage")
|
||||
t.Setenv("GO_ENV", "")
|
||||
|
||||
if IsDryRunAllowed() {
|
||||
t.Fatalf("expected dry-run to be disabled in stage")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsProductionEnv_FallsBackToGoEnv(t *testing.T) {
|
||||
originalAppEnv, hadAppEnv := os.LookupEnv("APP_ENV")
|
||||
if hadAppEnv {
|
||||
t.Cleanup(func() {
|
||||
_ = os.Setenv("APP_ENV", originalAppEnv)
|
||||
})
|
||||
} else {
|
||||
t.Cleanup(func() {
|
||||
_ = os.Unsetenv("APP_ENV")
|
||||
})
|
||||
}
|
||||
_ = os.Unsetenv("APP_ENV")
|
||||
t.Setenv("GO_ENV", "production")
|
||||
|
||||
if !IsProductionEnv() {
|
||||
t.Fatalf("expected GO_ENV=production fallback to be production-like")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user