go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/buildbucket/cli/commit_test.go (about) 1 // Copyright 2019 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 cli 16 17 import ( 18 "testing" 19 20 pb "go.chromium.org/luci/buildbucket/proto" 21 22 . "github.com/smartystreets/goconvey/convey" 23 . "go.chromium.org/luci/common/testing/assertions" 24 ) 25 26 func TestParseCommit(t *testing.T) { 27 Convey("ParseCommit", t, func() { 28 29 Convey("https://chromium.googlesource.com/infra/luci/luci-go/+/7a63166bfab5de38ddb2cb8e29aca756bdc2a28d", func() { 30 actual, confirm, err := parseCommit("https://chromium.googlesource.com/infra/luci/luci-go/+/7a63166bfab5de38ddb2cb8e29aca756bdc2a28d") 31 So(err, ShouldBeNil) 32 So(confirm, ShouldBeFalse) 33 So(actual, ShouldResembleProto, &pb.GitilesCommit{ 34 Host: "chromium.googlesource.com", 35 Project: "infra/luci/luci-go", 36 Ref: "", 37 Id: "7a63166bfab5de38ddb2cb8e29aca756bdc2a28d", 38 }) 39 }) 40 41 Convey("https://chromium.googlesource.com/infra/luci/luci-go/+/refs/heads/x", func() { 42 actual, confirm, err := parseCommit("https://chromium.googlesource.com/infra/luci/luci-go/+/refs/heads/x") 43 So(err, ShouldBeNil) 44 So(confirm, ShouldBeFalse) 45 So(actual, ShouldResembleProto, &pb.GitilesCommit{ 46 Host: "chromium.googlesource.com", 47 Project: "infra/luci/luci-go", 48 Ref: "refs/heads/x", 49 Id: "", 50 }) 51 }) 52 53 Convey("https://chromium.googlesource.com/infra/luci/luci-go/+/refs/tags/10.0.1", func() { 54 actual, confirm, err := parseCommit("https://chromium.googlesource.com/infra/luci/luci-go/+/refs/tags/10.0.1") 55 So(err, ShouldBeNil) 56 So(confirm, ShouldBeTrue) 57 So(actual, ShouldResembleProto, &pb.GitilesCommit{ 58 Host: "chromium.googlesource.com", 59 Project: "infra/luci/luci-go", 60 Ref: "refs/tags/10.0.1", 61 Id: "", 62 }) 63 }) 64 65 Convey("https://chromium.googlesource.com/infra/luci/luci-go/+/refs/heads/x/y", func() { 66 actual, confirm, err := parseCommit("https://chromium.googlesource.com/infra/luci/luci-go/+/refs/heads/x/y") 67 So(err, ShouldBeNil) 68 So(confirm, ShouldBeTrue) 69 So(actual, ShouldResembleProto, &pb.GitilesCommit{ 70 Host: "chromium.googlesource.com", 71 Project: "infra/luci/luci-go", 72 Ref: "refs/heads/x", 73 Id: "", 74 }) 75 }) 76 77 Convey("https://chromium.googlesource.com/infra/luci/luci-go/+/refs/branch-heads/x", func() { 78 actual, confirm, err := parseCommit("https://chromium.googlesource.com/infra/luci/luci-go/+/refs/branch-heads/x") 79 So(err, ShouldBeNil) 80 So(confirm, ShouldBeTrue) 81 So(actual, ShouldResembleProto, &pb.GitilesCommit{ 82 Host: "chromium.googlesource.com", 83 Project: "infra/luci/luci-go", 84 Ref: "refs/branch-heads/x", 85 Id: "", 86 }) 87 }) 88 89 Convey("https://chromium.googlesource.com/infra/luci/luci-go/+/main", func() { 90 actual, confirm, err := parseCommit("https://chromium.googlesource.com/infra/luci/luci-go/+/main") 91 So(err, ShouldBeNil) 92 So(confirm, ShouldBeTrue) 93 So(actual, ShouldResembleProto, &pb.GitilesCommit{ 94 Host: "chromium.googlesource.com", 95 Project: "infra/luci/luci-go", 96 Ref: "refs/heads/main", 97 Id: "", 98 }) 99 }) 100 101 Convey("https://chromium.googlesource.com/infra/luci/luci-go/+/refs/x", func() { 102 actual, confirm, err := parseCommit("https://chromium.googlesource.com/infra/luci/luci-go/+/refs/x") 103 So(err, ShouldBeNil) 104 So(confirm, ShouldBeTrue) 105 So(actual, ShouldResembleProto, &pb.GitilesCommit{ 106 Host: "chromium.googlesource.com", 107 Project: "infra/luci/luci-go", 108 Ref: "refs/x", 109 Id: "", 110 }) 111 }) 112 113 Convey("https://chromium-foo.googlesource.com/infra/luci/luci-go/+/refs/x", func() { 114 actual, confirm, err := parseCommit("https://chromium-foo.googlesource.com/infra/luci/luci-go/+/refs/x") 115 So(err, ShouldBeNil) 116 So(confirm, ShouldBeTrue) 117 So(actual, ShouldResembleProto, &pb.GitilesCommit{ 118 Host: "chromium-foo.googlesource.com", 119 Project: "infra/luci/luci-go", 120 Ref: "refs/x", 121 Id: "", 122 }) 123 }) 124 }) 125 }