k8s.io/test-infra@v0.0.0-20240520184403-27c6b4c223d8/experiment/ci-janitor/main_test.go (about)

     1  /*
     2  Copyright 2018 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  // ci-janitor cleans up dedicated projects in k8s prowjob configs
    18  package main
    19  
    20  import (
    21  	"testing"
    22  
    23  	v1 "k8s.io/api/core/v1"
    24  	"k8s.io/apimachinery/pkg/api/equality"
    25  	"k8s.io/apimachinery/pkg/util/diff"
    26  
    27  	"sigs.k8s.io/prow/pkg/config"
    28  )
    29  
    30  func TestContainers(t *testing.T) {
    31  	cases := []struct {
    32  		name     string
    33  		jb       config.JobBase
    34  		expected []v1.Container
    35  	}{
    36  		{
    37  			name: "only podspec",
    38  			jb: config.JobBase{
    39  				Spec: &v1.PodSpec{
    40  					Containers: []v1.Container{
    41  						{
    42  							Name: "hello",
    43  						},
    44  						{
    45  							Image: "there",
    46  						},
    47  					},
    48  				},
    49  			},
    50  			expected: []v1.Container{
    51  				{
    52  					Name: "hello",
    53  				},
    54  				{
    55  					Image: "there",
    56  				},
    57  			},
    58  		},
    59  	}
    60  
    61  	for _, tc := range cases {
    62  		t.Run(tc.name, func(t *testing.T) {
    63  			actual := containers(tc.jb)
    64  			if !equality.Semantic.DeepEqual(actual, tc.expected) {
    65  				t.Errorf("containers do not match:\n%s", diff.ObjectReflectDiff(tc.expected, actual))
    66  			}
    67  		})
    68  	}
    69  }