go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/client/cmd/cas/casimpl/scattergather_test.go (about) 1 // Copyright 2017 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 casimpl 16 17 import ( 18 "path/filepath" 19 "testing" 20 21 . "github.com/smartystreets/goconvey/convey" 22 ) 23 24 func TestScatterGatherAdd(t *testing.T) { 25 t.Parallel() 26 27 wd1 := filepath.Join("tmp", "go") 28 wd2 := filepath.Join("tmp", "stop") 29 rp1 := "ha" 30 rp2 := filepath.Join("hah", "bah") 31 rp3 := filepath.Join("hah", "nah") 32 rp3unclean := rp3 + "/" 33 34 Convey(`Test that Add works in a good case.`, t, func() { 35 sc := scatterGather{} 36 So(sc.Add(wd1, rp1), ShouldBeNil) 37 So(sc.Add(wd1, rp2), ShouldBeNil) 38 So(sc.Add(wd2, rp3unclean), ShouldBeNil) 39 40 So(sc, ShouldResemble, scatterGather{ 41 rp1: wd1, 42 rp2: wd1, 43 rp3: wd2, 44 }) 45 }) 46 47 Convey(`Test that Add fails in a bad case.`, t, func() { 48 sc := scatterGather{} 49 So(sc.Add(wd1, rp1), ShouldBeNil) 50 So(sc.Add(wd1, rp1), ShouldNotBeNil) 51 So(sc.Add(wd2, rp1), ShouldNotBeNil) 52 So(sc.Add(wd2, rp3), ShouldBeNil) 53 So(sc.Add(wd1, rp3unclean), ShouldNotBeNil) 54 }) 55 } 56 57 func TestScatterGatherSet(t *testing.T) { 58 t.Parallel() 59 60 Convey("Test that Set works in a good case.", t, func() { 61 sc := scatterGather{} 62 So(sc.Set("C:\\windir:dir"), ShouldBeNil) 63 So(sc.String(), ShouldEqual, "map[C:\\windir:[dir]]") 64 }) 65 }