go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/luciexe/host/options_test.go (about)

     1  // Copyright 2021 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 host
    16  
    17  import (
    18  	"testing"
    19  
    20  	bbpb "go.chromium.org/luci/buildbucket/proto"
    21  	"go.chromium.org/luci/logdog/client/butlerlib/streamproto"
    22  	"go.chromium.org/luci/logdog/common/viewer"
    23  
    24  	. "github.com/smartystreets/goconvey/convey"
    25  )
    26  
    27  func TestOptions(t *testing.T) {
    28  	Convey(`test Options`, t, func() {
    29  		Convey(`initialize sets logdogTags`, func() {
    30  			opts := Options{}
    31  			builder := &bbpb.BuilderID{
    32  				Builder: "builder-a",
    33  				Bucket:  "bucket-b",
    34  				Project: "proj-c",
    35  			}
    36  
    37  			Convey(`logdog viewer URL`, func() {
    38  				opts.ViewerURL = "https://example.org"
    39  
    40  				// w/ BaseBuild
    41  				opts.BaseBuild = &bbpb.Build{Builder: builder}
    42  				So(opts.initialize(), ShouldBeNil)
    43  				So(opts.logdogTags, ShouldResemble, streamproto.TagMap{
    44  					"buildbucket.builder":     "builder-a",
    45  					"buildbucket.bucket":      "bucket-b",
    46  					"buildbucket.project":     "proj-c",
    47  					viewer.LogDogViewerURLTag: "https://example.org",
    48  				})
    49  
    50  				// w/o BaseBuild
    51  				opts.BaseBuild = nil
    52  				So(opts.initialize(), ShouldBeNil)
    53  				So(opts.logdogTags, ShouldResemble, streamproto.TagMap{
    54  					viewer.LogDogViewerURLTag: "https://example.org",
    55  				})
    56  			})
    57  
    58  			Convey(`buildbucket`, func() {
    59  				opts.BaseBuild = &bbpb.Build{Builder: builder}
    60  
    61  				// w/ ViewerURL
    62  				// (this is done in the above convey
    63  
    64  				// w/o ViewerURL
    65  				opts.ViewerURL = ""
    66  				So(opts.initialize(), ShouldBeNil)
    67  				So(opts.logdogTags, ShouldResemble, streamproto.TagMap{
    68  					"buildbucket.builder": "builder-a",
    69  					"buildbucket.bucket":  "bucket-b",
    70  					"buildbucket.project": "proj-c",
    71  				})
    72  			})
    73  		})
    74  	})
    75  }