initializer_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright 2016 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 admission
  14. import (
  15. "testing"
  16. "k8s.io/apiserver/pkg/admission"
  17. )
  18. type doNothingAdmission struct{}
  19. func (doNothingAdmission) Admit(a admission.Attributes, o admission.ObjectInterfaces) error {
  20. return nil
  21. }
  22. func (doNothingAdmission) Handles(o admission.Operation) bool { return false }
  23. func (doNothingAdmission) Validate() error { return nil }
  24. type WantsCloudConfigAdmissionPlugin struct {
  25. doNothingAdmission
  26. cloudConfig []byte
  27. }
  28. func (p *WantsCloudConfigAdmissionPlugin) SetCloudConfig(cloudConfig []byte) {
  29. p.cloudConfig = cloudConfig
  30. }
  31. func TestCloudConfigAdmissionPlugin(t *testing.T) {
  32. cloudConfig := []byte("cloud-configuration")
  33. initializer := NewPluginInitializer(cloudConfig, nil, nil)
  34. wantsCloudConfigAdmission := &WantsCloudConfigAdmissionPlugin{}
  35. initializer.Initialize(wantsCloudConfigAdmission)
  36. if wantsCloudConfigAdmission.cloudConfig == nil {
  37. t.Errorf("Expected cloud config to be initialized but found nil")
  38. }
  39. }