go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/resultdb/internal/tasks/finalization_notify_test.go (about) 1 // Copyright 2022 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tasks 16 17 import ( 18 "context" 19 "testing" 20 21 "google.golang.org/protobuf/encoding/protojson" 22 23 "go.chromium.org/luci/resultdb/internal/testutil" 24 pb "go.chromium.org/luci/resultdb/proto/v1" 25 "go.chromium.org/luci/server/span" 26 "go.chromium.org/luci/server/tq" 27 28 . "github.com/smartystreets/goconvey/convey" 29 . "go.chromium.org/luci/common/testing/assertions" 30 ) 31 32 func TestNotifyInvocationFinalized(t *testing.T) { 33 t.Parallel() 34 35 Convey("With fake task queue scheduler", t, func() { 36 ctx := testutil.SpannerTestContext(t) 37 ctx, tq := tq.TestingContext(ctx, nil) 38 39 Convey("Enqueues a pub/sub notification", func() { 40 _, err := span.ReadWriteTransaction(ctx, func(ctx context.Context) error { 41 msg := &pb.InvocationFinalizedNotification{ 42 Invocation: "invocations/x", 43 Realm: "myproject:myrealm", 44 } 45 NotifyInvocationFinalized(ctx, msg) 46 return nil 47 }) 48 So(err, ShouldBeNil) 49 50 tasks := tq.Tasks() 51 So(tasks, ShouldHaveLength, 1) 52 t := tasks[0] 53 54 attrs := t.Message.GetAttributes() 55 So(attrs, ShouldContainKey, "luci_project") 56 So(attrs["luci_project"], ShouldEqual, "myproject") 57 58 var msg pb.InvocationFinalizedNotification 59 So(protojson.Unmarshal(t.Message.GetData(), &msg), ShouldBeNil) 60 So(&msg, ShouldResembleProto, &pb.InvocationFinalizedNotification{ 61 Invocation: "invocations/x", 62 Realm: "myproject:myrealm", 63 }) 64 }) 65 }) 66 }