go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/api/gitiles/common_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 gitiles 16 17 import ( 18 "testing" 19 20 . "github.com/smartystreets/goconvey/convey" 21 ) 22 23 func TestRepoURL(t *testing.T) { 24 t.Parallel() 25 Convey("Malformed", t, func() { 26 f := func(arg string) { 27 So(ValidateRepoURL(arg), ShouldNotBeNil) 28 _, err := NormalizeRepoURL(arg, true) 29 So(err, ShouldNotBeNil) 30 } 31 32 f("wtf/\\is\this") 33 f("https://example.com/repo.git") 34 f("http://bad-protocol.googlesource.com/repo.git") 35 f("https://a.googlesource.com") 36 f("https://a.googlesource.com/") 37 f("a.googlesource.com/no-protocol.git") 38 f("https://a.googlesource.com/no-protocol#fragment") 39 }) 40 41 Convey("OK", t, func() { 42 f := func(arg, exp string) { 43 So(ValidateRepoURL(arg), ShouldBeNil) 44 act, err := NormalizeRepoURL(arg, true) 45 So(err, ShouldBeNil) 46 So(act.String(), ShouldEqual, exp) 47 } 48 49 f("https://chromium.googlesource.com/repo.git", 50 "https://chromium.googlesource.com/a/repo") 51 f("https://chromium.googlesource.com/repo/", 52 "https://chromium.googlesource.com/a/repo") 53 f("https://chromium.googlesource.com/a/repo", 54 "https://chromium.googlesource.com/a/repo") 55 f("https://chromium.googlesource.com/parent/repo.git/", 56 "https://chromium.googlesource.com/a/parent/repo") 57 }) 58 }