Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect GAE_ENV=localdev #283

Merged
merged 1 commit into from Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/identity_vm.go
Expand Up @@ -131,5 +131,5 @@ func fullyQualifiedAppID(_ netcontext.Context) string {
}

func IsDevAppServer() bool {
return os.Getenv("RUN_WITH_DEVAPPSERVER") != ""
return os.Getenv("RUN_WITH_DEVAPPSERVER") != "" || os.Getenv("GAE_ENV") == "localdev"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: in the case where these two variable disagree (e.g. RUN_WITH_DEVAPPSERVER=1 GAE_ENV=standard) this code trusts the legacy RUN_WITH_DEVAPPSERVER over the new GAE_ENV. IMO this is the best option as it is less likely to break existing test environments that may be configured this way, and lets people start using the new variable in those envs. We can update this logic and/or totally remove RUN_WITH_DEVAPPSERVER in a later release.

}
2 changes: 1 addition & 1 deletion v2/internal/identity.go
Expand Up @@ -167,5 +167,5 @@ func fullyQualifiedAppID(_ netcontext.Context) string {
}

func IsDevAppServer() bool {
return os.Getenv("RUN_WITH_DEVAPPSERVER") != ""
return os.Getenv("RUN_WITH_DEVAPPSERVER") != "" || os.Getenv("GAE_ENV") == "localdev"
}
47 changes: 47 additions & 0 deletions v2/internal/identity_test.go
@@ -0,0 +1,47 @@
package internal

import (
"os"
"testing"
)

func TestIsDevAppServer(t *testing.T) {
tests := []struct {
desc string // See http://go/gotip/episodes/25 for naming guidance.
env map[string]string
want bool
}{
{desc: "empty", env: map[string]string{}, want: false},
{desc: "legacy", env: map[string]string{"RUN_WITH_DEVAPPSERVER": "1"}, want: true},
{desc: "new", env: map[string]string{"GAE_ENV": "localdev"}, want: true},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
for key, value := range test.env {
defer setenv(t, key, value)()
}
if got := IsDevAppServer(); got != test.want {
t.Errorf("env=%v IsDevAppServer() got %v, want %v", test.env, got, test.want)
}
})
}
}

// setenv is a backport of https://pkg.go.dev/testing#T.Setenv
func setenv(t *testing.T, key, value string) func() {
t.Helper()
prevValue, ok := os.LookupEnv(key)

if err := os.Setenv(key, value); err != nil {
t.Fatalf("cannot set environment variable: %v", err)
}

if ok {
return func() {
os.Setenv(key, prevValue)
}
}
return func() {
os.Unsetenv(key)
}
}