go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/resultdb/internal/exonerations/query_test.go (about) 1 // Copyright 2020 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 exonerations 16 17 import ( 18 "context" 19 "sort" 20 "testing" 21 22 . "github.com/smartystreets/goconvey/convey" 23 24 . "go.chromium.org/luci/common/testing/assertions" 25 "go.chromium.org/luci/resultdb/internal/invocations" 26 "go.chromium.org/luci/resultdb/internal/testutil" 27 "go.chromium.org/luci/resultdb/internal/testutil/insert" 28 "go.chromium.org/luci/resultdb/pbutil" 29 pb "go.chromium.org/luci/resultdb/proto/v1" 30 "go.chromium.org/luci/server/span" 31 ) 32 33 func TestQueryTestExonerations(t *testing.T) { 34 Convey(`QueryTestExonerations`, t, func() { 35 ctx := testutil.SpannerTestContext(t) 36 37 testutil.MustApply(ctx, testutil.CombineMutations( 38 insert.FinalizedInvocationWithInclusions("a", nil), 39 insert.FinalizedInvocationWithInclusions("b", nil), 40 insert.TestExonerations("a", "A", pbutil.Variant("v", "a"), pb.ExonerationReason_OCCURS_ON_OTHER_CLS, pb.ExonerationReason_NOT_CRITICAL), 41 insert.TestExonerations("b", "C", pbutil.Variant("v", "c"), pb.ExonerationReason_UNEXPECTED_PASS), 42 )...) 43 44 q := &Query{ 45 InvocationIDs: invocations.NewIDSet("a", "b"), 46 PageSize: 100, 47 } 48 actual, _, err := q.Fetch(span.Single(ctx)) 49 So(err, ShouldBeNil) 50 sort.Slice(actual, func(i, j int) bool { 51 return actual[i].Name < actual[j].Name 52 }) 53 So(actual, ShouldResembleProto, []*pb.TestExoneration{ 54 { 55 Name: "invocations/a/tests/A/exonerations/0", 56 TestId: "A", 57 Variant: pbutil.Variant("v", "a"), 58 ExonerationId: "0", 59 ExplanationHtml: "explanation 0", 60 VariantHash: pbutil.VariantHash(pbutil.Variant("v", "a")), 61 Reason: pb.ExonerationReason_OCCURS_ON_OTHER_CLS, 62 }, 63 { 64 Name: "invocations/a/tests/A/exonerations/1", 65 TestId: "A", 66 Variant: pbutil.Variant("v", "a"), 67 ExonerationId: "1", 68 ExplanationHtml: "explanation 1", 69 VariantHash: pbutil.VariantHash(pbutil.Variant("v", "a")), 70 Reason: pb.ExonerationReason_NOT_CRITICAL, 71 }, 72 { 73 Name: "invocations/b/tests/C/exonerations/0", 74 TestId: "C", 75 Variant: pbutil.Variant("v", "c"), 76 ExonerationId: "0", 77 ExplanationHtml: "explanation 0", 78 VariantHash: pbutil.VariantHash(pbutil.Variant("v", "c")), 79 Reason: pb.ExonerationReason_UNEXPECTED_PASS, 80 }, 81 }) 82 }) 83 } 84 85 func TestToLimitedData(t *testing.T) { 86 ctx := context.Background() 87 88 Convey(`ToLimitedData masks fields`, t, func() { 89 invocationID := "inv0" 90 testID := "FooBar" 91 exonerationID := "123" 92 name := pbutil.TestExonerationName(invocationID, testID, exonerationID) 93 variant := pbutil.Variant("v", "a") 94 variantHash := pbutil.VariantHash(variant) 95 96 testExoneration := &pb.TestExoneration{ 97 Name: name, 98 TestId: testID, 99 Variant: variant, 100 ExonerationId: exonerationID, 101 ExplanationHtml: "explanation 0", 102 VariantHash: variantHash, 103 Reason: pb.ExonerationReason_OCCURS_ON_OTHER_CLS, 104 } 105 106 expected := &pb.TestExoneration{ 107 Name: name, 108 TestId: testID, 109 ExonerationId: exonerationID, 110 ExplanationHtml: "explanation 0", 111 VariantHash: variantHash, 112 Reason: pb.ExonerationReason_OCCURS_ON_OTHER_CLS, 113 IsMasked: true, 114 } 115 116 err := ToLimitedData(ctx, testExoneration) 117 So(err, ShouldBeNil) 118 So(testExoneration, ShouldResembleProto, expected) 119 }) 120 }