go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/buildbucket/cli/cl_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 TestParseCL(t *testing.T) {
    27  	Convey("ParseCL", t, func() {
    28  
    29  		Convey("https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/1541677/7", func() {
    30  			actual, err := parseCL("https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/1541677/7")
    31  			So(err, ShouldBeNil)
    32  			So(actual, ShouldResembleProto, &pb.GerritChange{
    33  				Host:     "chromium-review.googlesource.com",
    34  				Project:  "infra/luci/luci-go",
    35  				Change:   1541677,
    36  				Patchset: 7,
    37  			})
    38  		})
    39  
    40  		Convey("https://chromium-review.googlesource.com/#/c/infra/luci/luci-go/+/1541677/7", func() {
    41  			actual, err := parseCL("https://chromium-review.googlesource.com/#/c/infra/luci/luci-go/+/1541677/7")
    42  			So(err, ShouldBeNil)
    43  			So(actual, ShouldResembleProto, &pb.GerritChange{
    44  				Host:     "chromium-review.googlesource.com",
    45  				Project:  "infra/luci/luci-go",
    46  				Change:   1541677,
    47  				Patchset: 7,
    48  			})
    49  		})
    50  
    51  		Convey("https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/1541677/7/buildbucket/cmd/bb/base_command.go", func() {
    52  			actual, err := parseCL("https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/1541677/7/buildbucket/cmd/bb/base_command.go")
    53  			So(err, ShouldBeNil)
    54  			So(actual, ShouldResembleProto, &pb.GerritChange{
    55  				Host:     "chromium-review.googlesource.com",
    56  				Project:  "infra/luci/luci-go",
    57  				Change:   1541677,
    58  				Patchset: 7,
    59  			})
    60  		})
    61  
    62  		Convey("https://chromium-review.googlesource.com/c/1541677/7", func() {
    63  			actual, err := parseCL("https://chromium-review.googlesource.com/c/1541677/7")
    64  			So(err, ShouldBeNil)
    65  			So(actual, ShouldResembleProto, &pb.GerritChange{
    66  				Host:     "chromium-review.googlesource.com",
    67  				Change:   1541677,
    68  				Patchset: 7,
    69  			})
    70  		})
    71  
    72  		Convey("https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/1541677", func() {
    73  			actual, err := parseCL("https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/1541677")
    74  			So(err, ShouldBeNil)
    75  			So(actual, ShouldResembleProto, &pb.GerritChange{
    76  				Host:    "chromium-review.googlesource.com",
    77  				Project: "infra/luci/luci-go",
    78  				Change:  1541677,
    79  			})
    80  		})
    81  
    82  		Convey("crrev.com/c/123", func() {
    83  			actual, err := parseCL("crrev.com/c/123")
    84  			So(err, ShouldBeNil)
    85  			So(actual, ShouldResembleProto, &pb.GerritChange{
    86  				Host:   "chromium-review.googlesource.com",
    87  				Change: 123,
    88  			})
    89  		})
    90  
    91  		Convey("crrev.com/c/123/4", func() {
    92  			actual, err := parseCL("crrev.com/c/123/4")
    93  			So(err, ShouldBeNil)
    94  			So(actual, ShouldResembleProto, &pb.GerritChange{
    95  				Host:     "chromium-review.googlesource.com",
    96  				Change:   123,
    97  				Patchset: 4,
    98  			})
    99  		})
   100  
   101  		Convey("crrev.com/i/123", func() {
   102  			actual, err := parseCL("crrev.com/i/123")
   103  			So(err, ShouldBeNil)
   104  			So(actual, ShouldResembleProto, &pb.GerritChange{
   105  				Host:   "chrome-internal-review.googlesource.com",
   106  				Change: 123,
   107  			})
   108  		})
   109  
   110  		Convey("https://crrev.com/i/123", func() {
   111  			actual, err := parseCL("https://crrev.com/i/123")
   112  			So(err, ShouldBeNil)
   113  			So(actual, ShouldResembleProto, &pb.GerritChange{
   114  				Host:   "chrome-internal-review.googlesource.com",
   115  				Change: 123,
   116  			})
   117  		})
   118  
   119  		Convey("https://chrome-internal-review.googlesource.com/c/src/+/1/2", func() {
   120  			actual, err := parseCL("https://chrome-internal-review.googlesource.com/c/src/+/1/2")
   121  			So(err, ShouldBeNil)
   122  			So(actual, ShouldResembleProto, &pb.GerritChange{
   123  				Host:     "chrome-internal-review.googlesource.com",
   124  				Project:  "src",
   125  				Change:   1,
   126  				Patchset: 2,
   127  			})
   128  		})
   129  	})
   130  }