aboutsummaryrefslogtreecommitdiff
path: root/internal/queue/queue_test.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2020-07-07 08:00:41 -0400
committerJonathan Amsterdam <jba@google.com>2020-07-07 14:09:24 +0000
commit41e1cccbb27a6960bda31600e32960cf99d31b51 (patch)
treead761db10e4659a804cfa6debfe26950e603110c /internal/queue/queue_test.go
parent154199566ce046ccfa931eeb6ba88ec89a0e5e6d (diff)
downloadgo-x-pkgsite-41e1cccbb27a6960bda31600e32960cf99d31b51.tar.xz
internal/config: have queue service default to GAE_SERVICE
If no GO_DISCOVERY_QUEUE_SERVICE is specified, default to the value of GAE_SERVICE. Without this, the QueueService config field is empty, so scheduled tasks are not delivered to the worker. Change-Id: Ia3d46f122208562c11c76dd0b857a0a5f6e5a822 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/241066 Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'internal/queue/queue_test.go')
-rw-r--r--internal/queue/queue_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/queue/queue_test.go b/internal/queue/queue_test.go
index 429e8017..e1150f13 100644
--- a/internal/queue/queue_test.go
+++ b/internal/queue/queue_test.go
@@ -5,8 +5,15 @@
package queue
import (
+ "context"
+ "os"
"testing"
"time"
+
+ "github.com/google/go-cmp/cmp"
+ "github.com/google/go-cmp/cmp/cmpopts"
+ "golang.org/x/pkgsite/internal/config"
+ taskspb "google.golang.org/genproto/googleapis/cloud/tasks/v2"
)
func TestNewTaskID(t *testing.T) {
@@ -28,3 +35,40 @@ func TestNewTaskID(t *testing.T) {
t.Error("wanted different task ID, got same")
}
}
+
+func TestNewTaskRequest(t *testing.T) {
+ for vari, val := range map[string]string{
+ "GOOGLE_CLOUD_PROJECT": "Project",
+ "GAE_SERVICE": "Service",
+ } {
+ 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)
+ }
+ const queueID = "queueID"
+ gcp := NewGCP(cfg, nil, queueID)
+ got := gcp.newTaskRequest("mod", "v1.2.3", "suf", time.Minute)
+ want := &taskspb.CreateTaskRequest{
+ Parent: "projects/Project/locations/us-central1/queues/" + queueID,
+ Task: &taskspb.Task{
+ MessageType: &taskspb.Task_AppEngineHttpRequest{
+ AppEngineHttpRequest: &taskspb.AppEngineHttpRequest{
+ HttpMethod: taskspb.HttpMethod_POST,
+ RelativeUri: "/fetch/mod/@v/v1.2.3",
+ AppEngineRouting: &taskspb.AppEngineRouting{
+ Service: "Service",
+ },
+ },
+ },
+ },
+ }
+ if diff := cmp.Diff(want, got, cmpopts.IgnoreFields(taskspb.Task{}, "Name")); diff != "" {
+ t.Errorf("mismatch (-want, +got):\n%s", diff)
+ }
+}