go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/resultdb/internal/invocations/graph/reachable_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 graph 16 17 import ( 18 "testing" 19 20 . "github.com/smartystreets/goconvey/convey" 21 22 . "go.chromium.org/luci/common/testing/assertions" 23 "go.chromium.org/luci/resultdb/internal/invocations" 24 "go.chromium.org/luci/resultdb/internal/testutil" 25 ) 26 27 func TestReachableInvocations(t *testing.T) { 28 Convey(`ReachableInvocations`, t, func() { 29 invs := NewReachableInvocations() 30 31 src1 := testutil.TestSourcesWithChangelistNumbers(12) 32 src2 := testutil.TestSourcesWithChangelistNumbers(13) 33 invs.Sources[HashSources(src1)] = src1 34 invs.Sources[HashSources(src2)] = src2 35 36 invs.Invocations["0"] = ReachableInvocation{HasTestResults: true, HasTestExonerations: true, Realm: "testproject:testrealmA", SourceHash: HashSources(src1)} 37 invs.Invocations["1"] = ReachableInvocation{HasTestResults: true, HasTestExonerations: false, Realm: "testproject:testrealmB"} 38 invs.Invocations["2"] = ReachableInvocation{HasTestResults: true, HasTestExonerations: true, Realm: "testproject:testrealmC"} 39 invs.Invocations["3"] = ReachableInvocation{HasTestResults: false, HasTestExonerations: false, Realm: "testproject:testrealmC", SourceHash: HashSources(src1)} 40 invs.Invocations["4"] = ReachableInvocation{HasTestResults: false, HasTestExonerations: true, Realm: "testproject:testrealmB", SourceHash: HashSources(src2)} 41 invs.Invocations["5"] = ReachableInvocation{HasTestResults: false, HasTestExonerations: false, Realm: "testproject:testrealmA"} 42 43 Convey(`Batches`, func() { 44 results := invs.batches(2) 45 So(results[0].Invocations, ShouldResemble, map[invocations.ID]ReachableInvocation{ 46 "3": {HasTestResults: false, HasTestExonerations: false, Realm: "testproject:testrealmC", SourceHash: HashSources(src1)}, 47 "4": {HasTestResults: false, HasTestExonerations: true, Realm: "testproject:testrealmB", SourceHash: HashSources(src2)}, 48 }) 49 So(results[0].Sources, ShouldHaveLength, 2) 50 So(results[0].Sources[HashSources(src1)], ShouldResembleProto, src1) 51 So(results[0].Sources[HashSources(src2)], ShouldResembleProto, src2) 52 53 So(results[1].Invocations, ShouldResemble, map[invocations.ID]ReachableInvocation{ 54 "0": {HasTestResults: true, HasTestExonerations: true, Realm: "testproject:testrealmA", SourceHash: HashSources(src1)}, 55 "1": {HasTestResults: true, HasTestExonerations: false, Realm: "testproject:testrealmB"}, 56 }) 57 So(results[1].Sources, ShouldHaveLength, 1) 58 So(results[1].Sources[HashSources(src1)], ShouldResembleProto, src1) 59 60 So(results[2].Invocations, ShouldResemble, map[invocations.ID]ReachableInvocation{ 61 "2": {HasTestResults: true, HasTestExonerations: true, Realm: "testproject:testrealmC"}, 62 "5": {HasTestResults: false, HasTestExonerations: false, Realm: "testproject:testrealmA"}, 63 }) 64 So(results[2].Sources, ShouldHaveLength, 0) 65 }) 66 Convey(`Marshal and unmarshal`, func() { 67 b, err := invs.marshal() 68 So(err, ShouldBeNil) 69 70 result, err := unmarshalReachableInvocations(b) 71 So(err, ShouldBeNil) 72 73 So(result.Invocations, ShouldResemble, invs.Invocations) 74 So(result.Sources, ShouldHaveLength, len(invs.Sources)) 75 for key, value := range invs.Sources { 76 So(result.Sources[key], ShouldResembleProto, value) 77 } 78 }) 79 Convey(`IDSet`, func() { 80 invIDs, err := invs.IDSet() 81 So(err, ShouldBeNil) 82 So(invIDs, ShouldResemble, invocations.NewIDSet("0", "1", "2", "3", "4", "5")) 83 }) 84 Convey(`WithTestResultsIDSet`, func() { 85 invIDs, err := invs.WithTestResultsIDSet() 86 So(err, ShouldBeNil) 87 So(invIDs, ShouldResemble, invocations.NewIDSet("0", "1", "2")) 88 }) 89 Convey(`WithExonerationsIDSet`, func() { 90 invIDs, err := invs.WithExonerationsIDSet() 91 So(err, ShouldBeNil) 92 So(invIDs, ShouldResemble, invocations.NewIDSet("0", "2", "4")) 93 }) 94 }) 95 }