Skip to content

Commit ea96ad2

Browse files
committed
internal/queue: fix TestNewTaskRequest
Instead of setting environment variables and calling config.Init, which can trigger code paths that can't work on some dev machines, just create a config in the test. Change-Id: Ie85dd86540f9bc11481f647a1856d4e4d828f150 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/251497 Reviewed-by: Julie Qiu <[email protected]> Reviewed-by: Miguel Acero <[email protected]> Run-TryBot: Julie Qiu <[email protected]> TryBot-Result: kokoro <[email protected]>
1 parent f152556 commit ea96ad2

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

internal/queue/queue_test.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
package queue
66

77
import (
8-
"context"
9-
"os"
108
"testing"
119
"time"
1210

@@ -39,15 +37,15 @@ func TestNewTaskID(t *testing.T) {
3937
func TestNewTaskRequest(t *testing.T) {
4038
for _, test := range []struct {
4139
name string
42-
env map[string]string
40+
cfg config.Config
4341
want *taskspb.CreateTaskRequest
4442
}{
4543
{
4644
"AppEngine",
47-
map[string]string{
48-
"GOOGLE_CLOUD_PROJECT": "Project",
49-
"GAE_SERVICE": "Service",
50-
"GAE_ENV": "standard",
45+
config.Config{
46+
ProjectID: "Project",
47+
LocationID: "us-central1",
48+
QueueService: "Service",
5149
},
5250
&taskspb.CreateTaskRequest{
5351
Parent: "projects/Project/locations/us-central1/queues/queueID",
@@ -66,9 +64,10 @@ func TestNewTaskRequest(t *testing.T) {
6664
},
6765
{
6866
"non-AppEngine",
69-
map[string]string{
70-
"GOOGLE_CLOUD_PROJECT": "Project",
71-
"GO_DISCOVERY_QUEUE_URL": "http://1.2.3.4:8000",
67+
config.Config{
68+
ProjectID: "Project",
69+
LocationID: "us-central1",
70+
QueueURL: "http://1.2.3.4:8000",
7271
},
7372
&taskspb.CreateTaskRequest{
7473
Parent: "projects/Project/locations/us-central1/queues/queueID",
@@ -84,18 +83,7 @@ func TestNewTaskRequest(t *testing.T) {
8483
},
8584
} {
8685
t.Run(test.name, func(t *testing.T) {
87-
for vari, val := range test.env {
88-
vari := vari
89-
prev := os.Getenv(vari)
90-
os.Setenv(vari, val)
91-
defer func() { os.Setenv(vari, prev) }()
92-
}
93-
94-
cfg, err := config.Init(context.Background())
95-
if err != nil {
96-
t.Fatal(err)
97-
}
98-
gcp, err := newGCP(cfg, nil, "queueID")
86+
gcp, err := newGCP(&test.cfg, nil, "queueID")
9987
if err != nil {
10088
t.Fatal(err)
10189
}

0 commit comments

Comments
 (0)