...

Source file src/k8s.io/kubernetes/pkg/kubelet/runtimeclass/runtimeclass_manager_test.go

Documentation: k8s.io/kubernetes/pkg/kubelet/runtimeclass

     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  package runtimeclass_test
    18  
    19  import (
    20  	"fmt"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  
    25  	"k8s.io/kubernetes/pkg/kubelet/runtimeclass"
    26  	rctest "k8s.io/kubernetes/pkg/kubelet/runtimeclass/testing"
    27  	"k8s.io/utils/pointer"
    28  )
    29  
    30  func TestLookupRuntimeHandler(t *testing.T) {
    31  	tests := []struct {
    32  		rcn         *string
    33  		expected    string
    34  		expectError bool
    35  	}{
    36  		{rcn: pointer.String(""), expected: ""},
    37  		{rcn: pointer.String(rctest.EmptyRuntimeClass), expected: ""},
    38  		{rcn: pointer.String(rctest.SandboxRuntimeClass), expected: "kata-containers"},
    39  		{rcn: pointer.String("phantom"), expectError: true},
    40  	}
    41  
    42  	manager := runtimeclass.NewManager(rctest.NewPopulatedClient())
    43  	defer rctest.StartManagerSync(manager)()
    44  
    45  	for _, test := range tests {
    46  		tname := "nil"
    47  		if test.rcn != nil {
    48  			tname = *test.rcn
    49  		}
    50  		t.Run(fmt.Sprintf("%q->%q(err:%v)", tname, test.expected, test.expectError), func(t *testing.T) {
    51  			handler, err := manager.LookupRuntimeHandler(test.rcn)
    52  			if test.expectError {
    53  				assert.Error(t, err, "handler=%q", handler)
    54  			} else {
    55  				assert.NoError(t, err)
    56  				assert.Equal(t, test.expected, handler)
    57  			}
    58  		})
    59  	}
    60  }
    61  

View as plain text