go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/bisection/model/changelogs_test.go (about)

     1  // Copyright 2022 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 model
    16  
    17  import (
    18  	"testing"
    19  	"time"
    20  
    21  	. "github.com/smartystreets/goconvey/convey"
    22  	"google.golang.org/protobuf/types/known/timestamppb"
    23  )
    24  
    25  func TestChangeLogs(t *testing.T) {
    26  	Convey("GetReviewUrl", t, func() {
    27  		cl := &ChangeLog{
    28  			Message: "",
    29  		}
    30  		_, err := cl.GetReviewUrl()
    31  		So(err, ShouldNotBeNil)
    32  		cl = &ChangeLog{
    33  			Message: "Use TestActivationManager for all page activations\n\nblah blah\n\nChange-Id: blah\nBug: blah\nReviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3472129\nReviewed-by: blah blah\n",
    34  		}
    35  		reviewUrl, err := cl.GetReviewUrl()
    36  		So(err, ShouldBeNil)
    37  		So(reviewUrl, ShouldEqual, "https://chromium-review.googlesource.com/c/chromium/src/+/3472129")
    38  	})
    39  
    40  	Convey("GetReviewTitle", t, func() {
    41  		cl := &ChangeLog{
    42  			Message: "",
    43  		}
    44  		reviewTitle, err := cl.GetReviewTitle()
    45  		So(err, ShouldNotBeNil)
    46  		So(reviewTitle, ShouldEqual, "")
    47  
    48  		cl = &ChangeLog{
    49  			Message: "Use TestActivationManager for all page activations\n\nblah blah\n\nChange-Id: blah\nBug: blah\nReviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3472129\nReviewed-by: blah blah\n",
    50  		}
    51  		reviewTitle, err = cl.GetReviewTitle()
    52  		So(err, ShouldBeNil)
    53  		So(reviewTitle, ShouldEqual, "Use TestActivationManager for all page activations")
    54  	})
    55  
    56  	Convey("Get commit time", t, func() {
    57  		cl := &ChangeLog{
    58  			Message: "",
    59  		}
    60  		_, err := cl.GetCommitTime()
    61  		So(err, ShouldNotBeNil)
    62  
    63  		cl = &ChangeLog{
    64  			Committer: ChangeLogActor{
    65  				Time: "Tue Oct 17 07:06:57 2023",
    66  			},
    67  		}
    68  		commitTime, err := cl.GetCommitTime()
    69  		So(err, ShouldBeNil)
    70  		So(commitTime, ShouldEqual, timestamppb.New(time.Date(2023, time.October, 17, 7, 6, 57, 0, time.UTC)))
    71  	})
    72  }