go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/led/job/edit_cipd_pkgs_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 job 16 17 import ( 18 "testing" 19 20 . "github.com/smartystreets/goconvey/convey" 21 . "go.chromium.org/luci/common/testing/assertions" 22 ) 23 24 func TestEditCIPDPkgs(t *testing.T) { 25 t.Parallel() 26 27 runCases(t, "EditCIPDPkgs", []testCase{ 28 { 29 name: "nil", 30 fn: func(jd *Definition) { 31 SoEdit(jd, func(je Editor) { 32 je.CIPDPkgs(nil) 33 }) 34 So(must(jd.Info().CIPDPkgs()), ShouldBeEmpty) 35 }, 36 }, 37 38 { 39 name: "add", 40 fn: func(jd *Definition) { 41 SoEdit(jd, func(je Editor) { 42 je.CIPDPkgs(CIPDPkgs{ 43 "subdir:some/pkg": "version", 44 "other_subdir:some/pkg": "different_version", 45 "some/other/pkg": "latest", 46 ":more/other/pkg": "whatever", 47 }) 48 }) 49 if sw := jd.GetSwarming(); sw != nil && len(sw.GetTask().GetTaskSlices()) == 0 { 50 So(must(jd.Info().CIPDPkgs()), ShouldBeEmpty) 51 } else { 52 So(must(jd.Info().CIPDPkgs()), ShouldResemble, CIPDPkgs{ 53 "subdir:some/pkg": "version", 54 "other_subdir:some/pkg": "different_version", 55 "some/other/pkg": "latest", 56 "more/other/pkg": "whatever", 57 }) 58 } 59 }, 60 }, 61 62 { 63 name: "delete", 64 fn: func(jd *Definition) { 65 SoEdit(jd, func(je Editor) { 66 je.CIPDPkgs(CIPDPkgs{ 67 "subdir:some/pkg": "version", 68 "other_subdir:some/pkg": "different_version", 69 "some/other/pkg": "latest", 70 }) 71 }) 72 SoEdit(jd, func(je Editor) { 73 je.CIPDPkgs(CIPDPkgs{ 74 "subdir:some/pkg": "", 75 "some/other/pkg": "", 76 }) 77 }) 78 79 if sw := jd.GetSwarming(); sw != nil && len(sw.GetTask().GetTaskSlices()) == 0 { 80 So(must(jd.Info().CIPDPkgs()), ShouldBeEmpty) 81 } else { 82 So(must(jd.Info().CIPDPkgs()), ShouldResemble, CIPDPkgs{ 83 "other_subdir:some/pkg": "different_version", 84 }) 85 } 86 }, 87 }, 88 89 { 90 name: "edit v2 build", 91 fn: func(jd *Definition) { 92 if b := jd.GetBuildbucket(); b != nil && b.BbagentDownloadCIPDPkgs() { 93 err := jd.Edit(func(je Editor) { 94 je.CIPDPkgs(CIPDPkgs{ 95 "subdir:some/pkg": "version", 96 }) 97 }) 98 So(err, ShouldErrLike, "not supported for Buildbucket v2 builds") 99 return 100 } 101 }, 102 v2Build: true, 103 }, 104 }) 105 }