go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/buildbucket/protoutil/step_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 protoutil 16 17 import ( 18 "testing" 19 20 . "github.com/smartystreets/goconvey/convey" 21 . "go.chromium.org/luci/common/testing/assertions" 22 ) 23 24 func TestParentStepName(t *testing.T) { 25 t.Parallel() 26 27 Convey("ParentStepName", t, func() { 28 Convey("with an empty name", func() { 29 So(ParentStepName(""), ShouldEqual, "") 30 }) 31 32 Convey("with a parent", func() { 33 So(ParentStepName("a|b"), ShouldEqual, "a") 34 So(ParentStepName("a|b|c"), ShouldEqual, "a|b") 35 So(ParentStepName("|b|"), ShouldEqual, "|b") 36 }) 37 38 Convey("without a paraent", func() { 39 So(ParentStepName("a.b"), ShouldEqual, "") 40 }) 41 }) 42 } 43 44 func TestValidateStepName(t *testing.T) { 45 t.Parallel() 46 47 Convey("Validate", t, func() { 48 Convey("with an empty name", func() { 49 So(ValidateStepName(""), ShouldErrLike, "required") 50 }) 51 52 Convey("with valid names", func() { 53 So(ValidateStepName("a"), ShouldBeNil) 54 So(ValidateStepName("a|b"), ShouldBeNil) 55 So(ValidateStepName("a|b|c"), ShouldBeNil) 56 }) 57 58 Convey("with invalid names", func() { 59 errMsg := `there must be at least one character before and after "|"` 60 So(ValidateStepName("|"), ShouldErrLike, errMsg) 61 So(ValidateStepName("a|"), ShouldErrLike, errMsg) 62 So(ValidateStepName("|a"), ShouldErrLike, errMsg) 63 So(ValidateStepName("a||b"), ShouldErrLike, errMsg) 64 }) 65 }) 66 }