Skip to content

Commit 716bdbc

Browse files
committed
Merge remote-tracking branch 'origin/main' into issues/3/main
# Conflicts: # environ.go
2 parents 8c4f7d6 + 6563f63 commit 716bdbc

File tree

4 files changed

+66
-12
lines changed

4 files changed

+66
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
out
55
gen
66

7+
# VSCode project files
8+
.vscode
9+
710
# Binaries for programs and plugins
811
*.exe
912
*.exe~

constant.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ package gcpen
33
const (
44
EnvKeyProjectID = "GCP_PROJECT" // for Google Cloud Functions
55
EnvKeyGoogleCloudProject = "GOOGLE_CLOUD_PROJECT" // for Google App Engine
6-
EnvKeyServiceName = "GAE_SERVICE" // for Google App Engine
7-
EnvKeyServiceVersion = "GAE_VERSION" // for Google App Engine
6+
7+
// Deprecated
8+
EnvKeyServiceName = "GAE_SERVICE" // for Google App Engine
9+
// Deprecated
10+
EnvKeyServiceVersion = "GAE_VERSION" // for Google App Engine
11+
12+
EnvKeyGAEServiceName = "GAE_SERVICE" // for Google App Engine
13+
EnvKeyGAEServiceVersion = "GAE_VERSION" // for Google App Engine
14+
EnvKeyRUNServiceName = "K_SERVICE" // for Google Cloud Run
15+
EnvKeyRUNServiceRevision = "K_REVISION" // for Google Cloud Run
816
)

environ.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,24 @@ import (
1010
var (
1111
// ProjectID - Google Cloud Platform Project ID
1212
ProjectID = getProjectID()
13+
1314
// ServiceName - Google App Engine service name
15+
// Deprecated
1416
ServiceName = os.Getenv(EnvKeyServiceName)
17+
1518
// ServiceVersion - Google App Engine service version
19+
// Deprecated
1620
ServiceVersion = os.Getenv(EnvKeyServiceVersion)
17-
projectNumber int64
21+
22+
// GAEServiceName - Google App Engine service name
23+
GAEServiceName = os.Getenv(EnvKeyGAEServiceName)
24+
// GAEServiceVersion - Google App Engine service version
25+
GAEServiceVersion = os.Getenv(EnvKeyGAEServiceVersion)
26+
// RUNServiceName - Google Cloud Run service name
27+
RUNServiceName = os.Getenv(EnvKeyRUNServiceName)
28+
// RUNServiceRevision - Google Cloud Run service revision
29+
RUNServiceRevision = os.Getenv(EnvKeyRUNServiceRevision)
30+
projectNumber int64
1831
)
1932

2033
func getProjectID() string {
@@ -34,8 +47,18 @@ func getProjectID() string {
3447
// Reload - Reload environment variables.
3548
func Reload() {
3649
ProjectID = getProjectID()
50+
51+
// Deprecated
52+
// ServiceName - Deprecated
3753
ServiceName = os.Getenv(EnvKeyServiceName)
54+
// Deprecated
55+
// ServiceVersion - Deprecated
3856
ServiceVersion = os.Getenv(EnvKeyServiceVersion)
57+
58+
GAEServiceName = os.Getenv(EnvKeyGAEServiceName)
59+
GAEServiceVersion = os.Getenv(EnvKeyGAEServiceVersion)
60+
RUNServiceName = os.Getenv(EnvKeyRUNServiceName)
61+
RUNServiceRevision = os.Getenv(EnvKeyRUNServiceRevision)
3962
}
4063

4164
// GetProjectNumber - get project number

environ_test.go

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,46 @@ import (
66
)
77

88
const (
9-
testProject = "test-project"
10-
testService = "test-service"
11-
testVersion = "test-version"
9+
testProject = "test-project"
10+
testGAEService = "test-gae-service"
11+
testGAEVersion = "test-gae-version"
12+
testRUNService = "test-run-service"
13+
testRUNRevision = "test-run-revision"
1214
)
1315

1416
func init() {
1517
os.Setenv(EnvKeyGoogleCloudProject, testProject)
16-
os.Setenv(EnvKeyServiceName, testService)
17-
os.Setenv(EnvKeyServiceVersion, testVersion)
18+
os.Setenv(EnvKeyGAEServiceName, testGAEService)
19+
os.Setenv(EnvKeyGAEServiceVersion, testGAEVersion)
20+
os.Setenv(EnvKeyRUNServiceName, testRUNService)
21+
os.Setenv(EnvKeyRUNServiceRevision, testRUNRevision)
1822
}
1923

2024
func TestEnviron(t *testing.T) {
2125
Reload()
2226
if ProjectID != testProject {
2327
t.Fatalf("unexpected, expected: %s, actual: %#v", testProject, ProjectID)
2428
}
25-
if ServiceName != testService {
26-
t.Fatalf("unexpected, expected: %s, actual: %#v", testService, ServiceName)
29+
30+
// Deprecated
31+
if ServiceName != testGAEService {
32+
t.Fatalf("unexpected, expected: %s, actual: %#v", testGAEService, ServiceName)
33+
}
34+
// Deprecated
35+
if ServiceVersion != testGAEVersion {
36+
t.Fatalf("unexpected, expected: %s, actual: %#v", testGAEVersion, ServiceVersion)
37+
}
38+
39+
if GAEServiceName != testGAEService {
40+
t.Fatalf("unexpected, expected: %s, actual: %#v", testGAEService, GAEServiceName)
41+
}
42+
if GAEServiceVersion != testGAEVersion {
43+
t.Fatalf("unexpected, expected: %s, actual: %#v", testGAEVersion, GAEServiceVersion)
44+
}
45+
if RUNServiceName != testRUNService {
46+
t.Fatalf("unexpected, expected: %s, actual: %#v", testRUNService, RUNServiceName)
2747
}
28-
if ServiceVersion != testVersion {
29-
t.Fatalf("unexpected, expected: %s, actual: %#v", testVersion, ServiceVersion)
48+
if RUNServiceRevision != testRUNRevision {
49+
t.Fatalf("unexpected, expected: %s, actual: %#v", testRUNRevision, RUNServiceRevision)
3050
}
3151
}

0 commit comments

Comments
 (0)