go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cipkg/base/generators/url_test.go (about) 1 // Copyright 2023 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 generators 16 17 import ( 18 "context" 19 "testing" 20 21 "go.chromium.org/luci/cipkg/core" 22 "go.chromium.org/luci/cipkg/internal/testutils" 23 "go.chromium.org/luci/common/testing/assertions" 24 25 . "github.com/smartystreets/goconvey/convey" 26 ) 27 28 func TestFetchURLs(t *testing.T) { 29 Convey("Test fetch urls", t, func() { 30 ctx := context.Background() 31 plats := Platforms{} 32 33 g := &FetchURLs{ 34 Name: "urls", 35 URLs: map[string]FetchURL{ 36 "something1": { 37 URL: "https://host/path1", 38 Mode: 0o777, 39 }, 40 "dir1/something2": { 41 URL: "https://host/path2", 42 HashAlgorithm: core.HashAlgorithm_HASH_MD5, 43 HashValue: "abcdef", 44 }, 45 }, 46 } 47 a, err := g.Generate(ctx, plats) 48 So(err, ShouldBeNil) 49 50 url := testutils.Assert[*core.Action_Copy](t, a.Spec) 51 So(url.Copy.Files, ShouldResemble, map[string]*core.ActionFilesCopy_Source{ 52 "something1": { 53 Content: &core.ActionFilesCopy_Source_Output_{ 54 Output: &core.ActionFilesCopy_Source_Output{Name: "urls_2o025r0794", Path: "file"}, 55 }, 56 Mode: 0o777, 57 }, 58 "dir1/something2": { 59 Content: &core.ActionFilesCopy_Source_Output_{ 60 Output: &core.ActionFilesCopy_Source_Output{Name: "urls_om04u163h4", Path: "file"}, 61 }, 62 Mode: 0o666, 63 }, 64 }) 65 66 { 67 So(a.Deps, ShouldHaveLength, 2) 68 for _, d := range a.Deps { 69 u := testutils.Assert[*core.Action_Url](t, d.Spec) 70 switch d.Name { 71 case "urls_2o025r0794": 72 So(u.Url, assertions.ShouldResembleProto, &core.ActionURLFetch{ 73 Url: "https://host/path1", 74 }) 75 case "urls_om04u163h4": 76 So(u.Url, assertions.ShouldResembleProto, &core.ActionURLFetch{ 77 Url: "https://host/path2", 78 HashAlgorithm: core.HashAlgorithm_HASH_MD5, 79 HashValue: "abcdef", 80 }) 81 } 82 } 83 } 84 }) 85 }