go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/luciexe/build/step_view_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 build 16 17 import ( 18 "context" 19 "testing" 20 21 . "github.com/smartystreets/goconvey/convey" 22 23 pb "go.chromium.org/luci/buildbucket/proto" 24 "go.chromium.org/luci/common/logging/memlogger" 25 26 . "go.chromium.org/luci/common/testing/assertions" 27 ) 28 29 func TestStepTags(t *testing.T) { 30 ctx := memlogger.Use(context.Background()) 31 32 Convey(`no tags added`, t, func() { 33 step := Step{ 34 ctx: ctx, 35 stepPb: &pb.Step{}, 36 } 37 step.AddTagValue("", "") 38 actualTags := step.stepPb.Tags 39 40 expectedTags := []*pb.StringPair(nil) 41 So(actualTags, ShouldResembleProto, expectedTags) 42 }) 43 44 Convey(`Add step tags`, t, func() { 45 step := Step{ 46 ctx: ctx, 47 stepPb: &pb.Step{}, 48 } 49 step.AddTagValue("build.testing.key", "value") 50 actualTags := step.stepPb.Tags 51 52 expectedTags := []*pb.StringPair{} 53 expectedTags = append(expectedTags, &pb.StringPair{ 54 Key: "build.testing.key", 55 Value: "value", 56 }) 57 So(actualTags, ShouldResembleProto, expectedTags) 58 }) 59 60 Convey(`Add step tag with existing key`, t, func() { 61 // One key may have multiple values 62 tags := []*pb.StringPair{} 63 tags = append(tags, &pb.StringPair{ 64 Key: "build.testing.key", 65 Value: "a", 66 }) 67 tags = append(tags, &pb.StringPair{ 68 Key: "build.testing.key", 69 Value: "g", 70 }) 71 step := Step{ 72 ctx: ctx, 73 stepPb: &pb.Step{ 74 Tags: tags, 75 }, 76 } 77 step.AddTagValue("build.testing.key", "d") 78 actualTags := step.stepPb.Tags 79 80 expectedTags := []*pb.StringPair{} 81 expectedTags = append(expectedTags, &pb.StringPair{ 82 Key: "build.testing.key", 83 Value: "a", 84 }) 85 expectedTags = append(expectedTags, &pb.StringPair{ 86 Key: "build.testing.key", 87 Value: "d", 88 }) 89 expectedTags = append(expectedTags, &pb.StringPair{ 90 Key: "build.testing.key", 91 Value: "g", 92 }) 93 So(actualTags, ShouldResembleProto, expectedTags) 94 }) 95 } 96 97 func TestSummaryMarkdown(t *testing.T) { 98 ctx := memlogger.Use(context.Background()) 99 100 Convey(`no summary markdown; one is added`, t, func() { 101 step := Step{ 102 ctx: ctx, 103 stepPb: &pb.Step{}, 104 } 105 step.SetSummaryMarkdown("test") 106 So(step.stepPb.SummaryMarkdown, ShouldEqual, "test") 107 }) 108 109 Convey(`existing summary markdown; then modified`, t, func() { 110 step := Step{ 111 ctx: ctx, 112 stepPb: &pb.Step{ 113 SummaryMarkdown: "test", 114 }, 115 } 116 step.SetSummaryMarkdown("some_really_cool_test_string") 117 So(step.stepPb.SummaryMarkdown, ShouldEqual, "some_really_cool_test_string") 118 }) 119 }