From ea96ad22b831e43f08898ad1ee93bb76bd5d48a9 Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Fri, 28 Aug 2020 14:09:15 -0400 Subject: 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 Reviewed-by: Miguel Acero Run-TryBot: Julie Qiu TryBot-Result: kokoro --- internal/queue/queue_test.go | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'internal/queue/queue_test.go') diff --git a/internal/queue/queue_test.go b/internal/queue/queue_test.go index eb0ce5b6..ddd810c8 100644 --- a/internal/queue/queue_test.go +++ b/internal/queue/queue_test.go @@ -5,8 +5,6 @@ package queue import ( - "context" - "os" "testing" "time" @@ -39,15 +37,15 @@ func TestNewTaskID(t *testing.T) { func TestNewTaskRequest(t *testing.T) { for _, test := range []struct { name string - env map[string]string + cfg config.Config want *taskspb.CreateTaskRequest }{ { "AppEngine", - map[string]string{ - "GOOGLE_CLOUD_PROJECT": "Project", - "GAE_SERVICE": "Service", - "GAE_ENV": "standard", + config.Config{ + ProjectID: "Project", + LocationID: "us-central1", + QueueService: "Service", }, &taskspb.CreateTaskRequest{ Parent: "projects/Project/locations/us-central1/queues/queueID", @@ -66,9 +64,10 @@ func TestNewTaskRequest(t *testing.T) { }, { "non-AppEngine", - map[string]string{ - "GOOGLE_CLOUD_PROJECT": "Project", - "GO_DISCOVERY_QUEUE_URL": "http://1.2.3.4:8000", + config.Config{ + ProjectID: "Project", + LocationID: "us-central1", + QueueURL: "http://1.2.3.4:8000", }, &taskspb.CreateTaskRequest{ Parent: "projects/Project/locations/us-central1/queues/queueID", @@ -84,18 +83,7 @@ func TestNewTaskRequest(t *testing.T) { }, } { t.Run(test.name, func(t *testing.T) { - for vari, val := range test.env { - vari := vari - prev := os.Getenv(vari) - os.Setenv(vari, val) - defer func() { os.Setenv(vari, prev) }() - } - - cfg, err := config.Init(context.Background()) - if err != nil { - t.Fatal(err) - } - gcp, err := newGCP(cfg, nil, "queueID") + gcp, err := newGCP(&test.cfg, nil, "queueID") if err != nil { t.Fatal(err) } -- cgit v1.3-5-g45d5