initializer_test.go 1.5 KB

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