go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/frontend/view_build_test.go (about)

     1  // Copyright 2017 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 frontend
    16  
    17  import (
    18  	"testing"
    19  
    20  	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
    21  
    22  	. "github.com/smartystreets/goconvey/convey"
    23  )
    24  
    25  func TestPrepareGetBuildRequest(t *testing.T) {
    26  	t.Parallel()
    27  
    28  	Convey(`TestPrepareGetBuildRequest`, t, func() {
    29  		builderID := &buildbucketpb.BuilderID{
    30  			Project: "fake-project",
    31  			Bucket:  "fake-bucket",
    32  			Builder: "fake-builder",
    33  		}
    34  
    35  		Convey("Should parse build number correctly", func() {
    36  			req, err := prepareGetBuildRequest(builderID, "123")
    37  			So(err, ShouldBeNil)
    38  			So(req.BuildNumber, ShouldEqual, 123)
    39  			So(req.Builder, ShouldEqual, builderID)
    40  		})
    41  
    42  		Convey("Should reject large build number", func() {
    43  			req, err := prepareGetBuildRequest(builderID, "9223372036854775807")
    44  			So(err, ShouldNotBeNil)
    45  			So(req, ShouldBeNil)
    46  		})
    47  
    48  		Convey("Should reject malformated build number", func() {
    49  			req, err := prepareGetBuildRequest(builderID, "abc")
    50  			So(err, ShouldNotBeNil)
    51  			So(req, ShouldBeNil)
    52  		})
    53  
    54  		Convey("Should parse build ID correctly", func() {
    55  			req, err := prepareGetBuildRequest(builderID, "b123")
    56  			So(err, ShouldBeNil)
    57  			So(req.Id, ShouldEqual, 123)
    58  			So(req.Builder, ShouldBeNil)
    59  		})
    60  
    61  		Convey("Should reject large build ID", func() {
    62  			req, err := prepareGetBuildRequest(builderID, "b9223372036854775809")
    63  			So(err, ShouldNotBeNil)
    64  			So(req, ShouldBeNil)
    65  		})
    66  	})
    67  }