go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/led/job/info_test.go (about)

     1  // Copyright 2020 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 job
    16  
    17  import (
    18  	"testing"
    19  
    20  	bbpb "go.chromium.org/luci/buildbucket/proto"
    21  	swarmingpb "go.chromium.org/luci/swarming/proto/api_v2"
    22  
    23  	. "github.com/smartystreets/goconvey/convey"
    24  	. "go.chromium.org/luci/common/testing/assertions"
    25  )
    26  
    27  func TestGetCurrentIsolated(t *testing.T) {
    28  	t.Parallel()
    29  
    30  	Convey(`GetCurrentIsolated`, t, func() {
    31  		Convey(`none (bb)`, func() {
    32  			current, err := testBBJob(false).Info().CurrentIsolated()
    33  			So(err, ShouldBeNil)
    34  			So(current, ShouldBeNil)
    35  		})
    36  
    37  		Convey(`CasUserPayload`, func() {
    38  			jd := testBBJob(false)
    39  			jd.GetBuildbucket().BbagentArgs = &bbpb.BBAgentArgs{
    40  				Build: &bbpb.Build{
    41  					Infra: &bbpb.BuildInfra{
    42  						Buildbucket: &bbpb.BuildInfra_Buildbucket{
    43  							Agent: &bbpb.BuildInfra_Buildbucket_Agent{
    44  								Input: &bbpb.BuildInfra_Buildbucket_Agent_Input{
    45  									Data: map[string]*bbpb.InputDataRef{
    46  										"payload_path": {
    47  											DataType: &bbpb.InputDataRef_Cas{
    48  												Cas: &bbpb.InputDataRef_CAS{
    49  													Digest: &bbpb.InputDataRef_CAS_Digest{
    50  														Hash: "hash",
    51  													},
    52  												},
    53  											},
    54  										},
    55  									},
    56  								},
    57  								Purposes: map[string]bbpb.BuildInfra_Buildbucket_Agent_Purpose{
    58  									"payload_path": bbpb.BuildInfra_Buildbucket_Agent_PURPOSE_EXE_PAYLOAD,
    59  								},
    60  							},
    61  						},
    62  					},
    63  				},
    64  			}
    65  			current, err := jd.Info().CurrentIsolated()
    66  			So(err, ShouldBeNil)
    67  			So(current, ShouldResembleProto, &swarmingpb.CASReference{Digest: &swarmingpb.Digest{Hash: "hash"}})
    68  		})
    69  
    70  		Convey(`Swarming`, func() {
    71  			Convey(`rbe-cas`, func() {
    72  				Convey(`one slice`, func() {
    73  					jd := testSWJob()
    74  					jd.GetSwarming().Task = &swarmingpb.NewTaskRequest{
    75  						TaskSlices: []*swarmingpb.TaskSlice{
    76  							{
    77  								Properties: &swarmingpb.TaskProperties{CasInputRoot: &swarmingpb.CASReference{
    78  									Digest: &swarmingpb.Digest{Hash: "hash"},
    79  								}},
    80  							},
    81  						},
    82  					}
    83  					current, err := jd.Info().CurrentIsolated()
    84  					So(err, ShouldBeNil)
    85  					So(current, ShouldResembleProto, &swarmingpb.CASReference{Digest: &swarmingpb.Digest{Hash: "hash"}})
    86  				})
    87  
    88  				Convey(`slice+CasUserPayload (match)`, func() {
    89  					jd := testSWJob()
    90  					jd.GetSwarming().CasUserPayload = &swarmingpb.CASReference{CasInstance: "instance"}
    91  					jd.GetSwarming().Task = &swarmingpb.NewTaskRequest{
    92  						TaskSlices: []*swarmingpb.TaskSlice{
    93  							{
    94  								Properties: &swarmingpb.TaskProperties{CasInputRoot: &swarmingpb.CASReference{
    95  									Digest: &swarmingpb.Digest{Hash: "hash"},
    96  								}},
    97  							},
    98  						},
    99  					}
   100  					current, err := jd.Info().CurrentIsolated()
   101  					So(err, ShouldBeNil)
   102  					So(current, ShouldResembleProto, &swarmingpb.CASReference{Digest: &swarmingpb.Digest{Hash: "hash"}})
   103  				})
   104  
   105  				Convey(`slice+CasUserPayload (mismatch)`, func() {
   106  					jd := testSWJob()
   107  					jd.GetSwarming().CasUserPayload = &swarmingpb.CASReference{Digest: &swarmingpb.Digest{Hash: "new hash"}}
   108  					jd.GetSwarming().Task = &swarmingpb.NewTaskRequest{
   109  						TaskSlices: []*swarmingpb.TaskSlice{
   110  							{
   111  								Properties: &swarmingpb.TaskProperties{CasInputRoot: &swarmingpb.CASReference{
   112  									Digest: &swarmingpb.Digest{Hash: "hash"},
   113  								}},
   114  							},
   115  						},
   116  					}
   117  					_, err := jd.Info().CurrentIsolated()
   118  					So(err, ShouldErrLike, "Definition contains multiple RBE-CAS inputs")
   119  				})
   120  			})
   121  		})
   122  	})
   123  }