diff options
| author | Michael Matloob <matloob@golang.org> | 2023-07-18 15:09:40 -0400 |
|---|---|---|
| committer | Michael Matloob <matloob@golang.org> | 2023-07-19 19:28:32 +0000 |
| commit | 96b17712a822c1eded85e478adfa1244b1990d8e (patch) | |
| tree | fee2394061147b0110636f2a5b4a9ba61a4847e4 /internal/queue/gcpqueue/queue_test.go | |
| parent | 64dbd74b14032a5f58252a47fd85377381f3610f (diff) | |
| download | go-x-pkgsite-96b17712a822c1eded85e478adfa1244b1990d8e.tar.xz | |
internal/queue: split out gcp queue into different package
internal/frontend depends on internal/queue. Move the parts with gcp
dependencies into its own package so internal/frontend no longer has
those gcp queue dependencies.
For #61399
Change-Id: I0083c31da1b367f135e53686e4c994d7c4d6420f
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/510815
TryBot-Result: Gopher Robot <gobot@golang.org>
kokoro-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'internal/queue/gcpqueue/queue_test.go')
| -rw-r--r-- | internal/queue/gcpqueue/queue_test.go | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/internal/queue/gcpqueue/queue_test.go b/internal/queue/gcpqueue/queue_test.go new file mode 100644 index 00000000..cbe92e78 --- /dev/null +++ b/internal/queue/gcpqueue/queue_test.go @@ -0,0 +1,81 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package gcpqueue + +import ( + "golang.org/x/pkgsite/internal/queue" + "testing" + + "github.com/google/go-cmp/cmp" + "golang.org/x/pkgsite/internal/config" + taskspb "google.golang.org/genproto/googleapis/cloud/tasks/v2" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/durationpb" +) + +func TestNewTaskID(t *testing.T) { + for _, test := range []struct { + modulePath, version string + want string + }{ + {"m-1", "v2", "acc5-m-1_vv2"}, + {"my_module", "v1.2.3", "0cb9-my__module_vv1_o2_o3"}, + {"µπΩ/github.com", "v2.3.4-ß", "a49c-_00b5_03c0_03a9_-github_ocom_vv2_o3_o4-_00df"}, + } { + got := newTaskID(test.modulePath, test.version) + if got != test.want { + t.Errorf("%s@%s: got %s, want %s", test.modulePath, test.version, got, test.want) + } + } +} + +func TestNewTaskRequest(t *testing.T) { + cfg := config.Config{ + ProjectID: "Project", + LocationID: "us-central1", + QueueURL: "http://1.2.3.4:8000", + ServiceAccount: "sa", + QueueAudience: "qa", + } + want := &taskspb.CreateTaskRequest{ + Parent: "projects/Project/locations/us-central1/queues/queueID", + Task: &taskspb.Task{ + DispatchDeadline: durationpb.New(maxCloudTasksTimeout), + MessageType: &taskspb.Task_HttpRequest{ + HttpRequest: &taskspb.HttpRequest{ + HttpMethod: taskspb.HttpMethod_POST, + Url: "http://1.2.3.4:8000/fetch/mod/@v/v1.2.3", + AuthorizationHeader: &taskspb.HttpRequest_OidcToken{ + OidcToken: &taskspb.OidcToken{ + ServiceAccountEmail: "sa", + Audience: "qa", + }, + }, + }, + }, + }, + } + gcp, err := newGCP(&cfg, nil, "queueID") + if err != nil { + t.Fatal(err) + } + opts := &queue.Options{ + Suffix: "suf", + } + got := gcp.newTaskRequest("mod", "v1.2.3", opts) + want.Task.Name = got.Task.Name + if diff := cmp.Diff(want, got, cmp.Comparer(proto.Equal)); diff != "" { + t.Errorf("mismatch (-want, +got):\n%s", diff) + } + + want.Task.MessageType.(*taskspb.Task_HttpRequest).HttpRequest.Url += "?proxyfetch=off" + opts.DisableProxyFetch = true + got = gcp.newTaskRequest("mod", "v1.2.3", opts) + want.Task.Name = got.Task.Name + if diff := cmp.Diff(want, got, cmp.Comparer(proto.Equal)); diff != "" { + t.Errorf("mismatch (-want, +got):\n%s", diff) + } + +} |
