github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/pkg/scheduler/strategy/default_test.go (about)

     1  /*
     2  Copyright 2024 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package strategy_test
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/google/go-cmp/cmp"
    24  	prowv1 "sigs.k8s.io/prow/pkg/apis/prowjobs/v1"
    25  	"sigs.k8s.io/prow/pkg/scheduler/strategy"
    26  )
    27  
    28  func TestPassthrough(t *testing.T) {
    29  	for _, tc := range []struct {
    30  		name       string
    31  		pj         *prowv1.ProwJob
    32  		wantResult strategy.Result
    33  	}{
    34  		{
    35  			name:       "Get the same cluster found on a Prowjob",
    36  			pj:         &prowv1.ProwJob{Spec: prowv1.ProwJobSpec{Cluster: "build-cluster"}},
    37  			wantResult: strategy.Result{Cluster: "build-cluster"},
    38  		},
    39  		{
    40  			name:       "Empty cluster in, empty cluster out",
    41  			pj:         &prowv1.ProwJob{},
    42  			wantResult: strategy.Result{},
    43  		},
    44  	} {
    45  		tc := tc
    46  		t.Run(tc.name, func(t *testing.T) {
    47  			t.Parallel()
    48  
    49  			passthrough := strategy.Passthrough{}
    50  			result, err := passthrough.Schedule(context.TODO(), tc.pj)
    51  
    52  			if err != nil {
    53  				t.Errorf("Unexpected error: %s", err)
    54  			}
    55  
    56  			if diff := cmp.Diff(tc.wantResult, result); diff != "" {
    57  				t.Errorf("Unexpected result: %s", diff)
    58  			}
    59  		})
    60  	}
    61  }