diff options
| author | Jonathan Amsterdam <jba@google.com> | 2020-08-28 14:09:15 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2020-08-28 18:38:22 +0000 |
| commit | ea96ad22b831e43f08898ad1ee93bb76bd5d48a9 (patch) | |
| tree | 5a8032e5434b5dcebdc3746b61900646c88199c5 /internal/queue/queue_test.go | |
| parent | f152556308a5edc00685789e1ee5259e7d3950ab (diff) | |
| download | go-x-pkgsite-ea96ad22b831e43f08898ad1ee93bb76bd5d48a9.tar.xz | |
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 <julie@golang.org>
Reviewed-by: Miguel Acero <acero@google.com>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'internal/queue/queue_test.go')
| -rw-r--r-- | internal/queue/queue_test.go | 32 |
1 files changed, 10 insertions, 22 deletions
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) } |
