go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/resultdb/internal/baselines/baselines_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 baselines
    16  
    17  import (
    18  	"testing"
    19  	"time"
    20  
    21  	. "github.com/smartystreets/goconvey/convey"
    22  
    23  	. "go.chromium.org/luci/common/testing/assertions"
    24  	"go.chromium.org/luci/server/span"
    25  
    26  	"go.chromium.org/luci/resultdb/internal/testutil"
    27  )
    28  
    29  func TestRead(t *testing.T) {
    30  	Convey(`Invalid`, t, func() {
    31  		ctx := testutil.SpannerTestContext(t)
    32  
    33  		Convey(`Not Found`, func() {
    34  			_, err := Read(span.Single(ctx), "chromium", "try:linux-rel")
    35  			So(err, ShouldErrLike, NotFound)
    36  		})
    37  
    38  	})
    39  
    40  	Convey(`Valid`, t, func() {
    41  		ctx := testutil.SpannerTestContext(t)
    42  
    43  		Convey(`Exists`, func() {
    44  			expected := &Baseline{
    45  				Project:    "chromium",
    46  				BaselineID: "try:linux-rel",
    47  			}
    48  			commitTime := testutil.MustApply(ctx, Create(expected.Project, expected.BaselineID))
    49  
    50  			res, err := Read(span.Single(ctx), expected.Project, expected.BaselineID)
    51  			So(err, ShouldBeNil)
    52  			So(res.Project, ShouldEqual, expected.Project)
    53  			So(res.BaselineID, ShouldEqual, expected.BaselineID)
    54  			So(res.LastUpdatedTime, ShouldEqual, commitTime)
    55  			So(res.CreationTime, ShouldEqual, commitTime)
    56  		})
    57  	})
    58  }
    59  
    60  func TestIsSpinningUp(t *testing.T) {
    61  	Convey(`IsSpinningUp`, t, func() {
    62  		now := time.Date(2026, 1, 2, 3, 4, 5, 6, time.UTC)
    63  
    64  		Convey(`Yes`, func() {
    65  			b := &Baseline{
    66  				Project:         "chromium",
    67  				BaselineID:      "try:linux-rel",
    68  				LastUpdatedTime: now.Add(-time.Hour * 1),
    69  				CreationTime:    now.Add(-time.Hour * 2),
    70  			}
    71  			So(b.IsSpinningUp(now), ShouldBeTrue)
    72  		})
    73  
    74  		Convey(`No`, func() {
    75  			b := &Baseline{
    76  				Project:         "chromium",
    77  				BaselineID:      "try:linux-rel",
    78  				LastUpdatedTime: now.Add(-time.Hour * 1),
    79  				CreationTime:    now.Add(-time.Hour * 100),
    80  			}
    81  			So(b.IsSpinningUp(now), ShouldBeFalse)
    82  		})
    83  	})
    84  }