go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/resultdb/internal/baselines/testvariants/baseline_testvariants_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 baselinetestvariant
    16  
    17  import (
    18  	"testing"
    19  
    20  	. "github.com/smartystreets/goconvey/convey"
    21  
    22  	. "go.chromium.org/luci/common/testing/assertions"
    23  	"go.chromium.org/luci/server/span"
    24  
    25  	"go.chromium.org/luci/resultdb/internal/testutil"
    26  )
    27  
    28  func TestRead(t *testing.T) {
    29  	Convey(`Invalid`, t, func() {
    30  		ctx := testutil.SpannerTestContext(t)
    31  
    32  		Convey(`Not Found`, func() {
    33  			_, err := Read(span.Single(ctx), "chromium", "try:linux-rel", "ninja://some/test:test_id", "12345")
    34  			So(err, ShouldErrLike, NotFound)
    35  		})
    36  
    37  	})
    38  
    39  	Convey(`Valid`, t, func() {
    40  		ctx := testutil.SpannerTestContext(t)
    41  
    42  		Convey(`Exists`, func() {
    43  			exp := &BaselineTestVariant{
    44  				Project:     "chromium",
    45  				BaselineID:  "try:linux-rel",
    46  				TestID:      "ninja://some/test:test_id",
    47  				VariantHash: "12345",
    48  			}
    49  			commitTime := testutil.MustApply(ctx, Create(exp.Project, exp.BaselineID, exp.TestID, exp.VariantHash))
    50  
    51  			res, err := Read(span.Single(ctx), exp.Project, exp.BaselineID, exp.TestID, exp.VariantHash)
    52  			So(err, ShouldBeNil)
    53  			So(res.Project, ShouldEqual, exp.Project)
    54  			So(res.BaselineID, ShouldEqual, exp.BaselineID)
    55  			So(res.TestID, ShouldEqual, exp.TestID)
    56  			So(res.VariantHash, ShouldEqual, exp.VariantHash)
    57  			So(res.LastUpdated, ShouldEqual, commitTime)
    58  		})
    59  	})
    60  }