Skip to content

Commit

Permalink
add APP_ENV as app environment key
Browse files Browse the repository at this point in the history
  • Loading branch information
lalabuy948 committed Aug 17, 2020
1 parent 3a9364b commit c7a31e0
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
18 changes: 18 additions & 0 deletions gonvutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ func IsProduction() bool {
if os.Getenv("ENVIRONMENT") == "PRODUCTION" {
return true
}
if os.Getenv("APP_ENV") == "PROD" {
return true
}
if os.Getenv("APP_ENV") == "PRODUCTION" {
return true
}
return false
}

Expand All @@ -22,6 +28,12 @@ func IsDevelopment() bool {
if os.Getenv("ENVIRONMENT") == "DEVELOPMENT" {
return true
}
if os.Getenv("APP_ENV") == "DEV" {
return true
}
if os.Getenv("APP_ENV") == "DEVELOPMENT" {
return true
}
return false
}

Expand All @@ -33,6 +45,12 @@ func IsTesting() bool {
if os.Getenv("ENVIRONMENT") == "TESTING" {
return true
}
if os.Getenv("APP_ENV") == "TEST" {
return true
}
if os.Getenv("APP_ENV") == "TESTING" {
return true
}
return false
}

Expand Down
57 changes: 57 additions & 0 deletions gonvutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,26 @@ func TestIsProduction(t *testing.T) {
t.Errorf("IsProduction() = %v; want false", got)
}

os.Setenv("APP_ENV", "PROD")
got = IsProduction()
if got != true {
t.Errorf("IsProduction() = %v; want true", got)
}

os.Setenv("APP_ENV", "PRODUCTION")
got = IsProduction()
if got != true {
t.Errorf("IsProduction() = %v; want true", got)
}

os.Setenv("APP_ENV", "BLA")
got = IsProduction()
if got != false {
t.Errorf("IsProduction() = %v; want false", got)
}

os.Unsetenv("ENVIRONMENT")
os.Unsetenv("APP_ENV")
}

func TestIsDevelopment(t *testing.T) {
Expand All @@ -46,7 +65,26 @@ func TestIsDevelopment(t *testing.T) {
t.Errorf("IsDevelopment() = %v; want false", got)
}

os.Setenv("APP_ENV", "DEV")
got = IsDevelopment()
if got != true {
t.Errorf("IsDevelopment() = %v; want true", got)
}

os.Setenv("APP_ENV", "DEVELOPMENT")
got = IsDevelopment()
if got != true {
t.Errorf("IsDevelopment() = %v; want true", got)
}

os.Setenv("APP_ENV", "BLA")
got = IsDevelopment()
if got != false {
t.Errorf("IsDevelopment() = %v; want false", got)
}

os.Unsetenv("ENVIRONMENT")
os.Unsetenv("APP_ENV")
}

func TestIsTesting(t *testing.T) {
Expand All @@ -68,7 +106,26 @@ func TestIsTesting(t *testing.T) {
t.Errorf("IsTesting() = %v; want false", got)
}

os.Setenv("APP_ENV", "TEST")
got = IsTesting()
if got != true {
t.Errorf("IsTesting() = %v; want true", got)
}

os.Setenv("APP_ENV", "TESTING")
got = IsTesting()
if got != true {
t.Errorf("IsTesting() = %v; want true", got)
}

os.Setenv("APP_ENV", "BLA")
got = IsTesting()
if got != false {
t.Errorf("IsTesting() = %v; want false", got)
}

os.Unsetenv("ENVIRONMENT")
os.Unsetenv("APP_ENV")
}

func TestGetEnv(t *testing.T) {
Expand Down

0 comments on commit c7a31e0

Please sign in to comment.