runtimeclass_manager_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package runtimeclass_test
  14. import (
  15. "fmt"
  16. "testing"
  17. "github.com/stretchr/testify/assert"
  18. "k8s.io/kubernetes/pkg/kubelet/runtimeclass"
  19. rctest "k8s.io/kubernetes/pkg/kubelet/runtimeclass/testing"
  20. "k8s.io/utils/pointer"
  21. )
  22. func TestLookupRuntimeHandler(t *testing.T) {
  23. tests := []struct {
  24. rcn *string
  25. expected string
  26. expectError bool
  27. }{
  28. {rcn: pointer.StringPtr(""), expected: ""},
  29. {rcn: pointer.StringPtr(rctest.EmptyRuntimeClass), expected: ""},
  30. {rcn: pointer.StringPtr(rctest.SandboxRuntimeClass), expected: "kata-containers"},
  31. {rcn: pointer.StringPtr("phantom"), expectError: true},
  32. }
  33. manager := runtimeclass.NewManager(rctest.NewPopulatedClient())
  34. defer rctest.StartManagerSync(manager)()
  35. for _, test := range tests {
  36. tname := "nil"
  37. if test.rcn != nil {
  38. tname = *test.rcn
  39. }
  40. t.Run(fmt.Sprintf("%q->%q(err:%v)", tname, test.expected, test.expectError), func(t *testing.T) {
  41. handler, err := manager.LookupRuntimeHandler(test.rcn)
  42. if test.expectError {
  43. assert.Error(t, err, "handler=%q", handler)
  44. } else {
  45. assert.NoError(t, err)
  46. assert.Equal(t, test.expected, handler)
  47. }
  48. })
  49. }
  50. }