podtemplatespec.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright 2019 The Rook Authors. All rights reserved.
  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 test
  14. import (
  15. "testing"
  16. v1 "k8s.io/api/core/v1"
  17. )
  18. // A PodTemplateSpecTester is a helper exposing methods for testing required Rook specifications
  19. // common for all Rook PodTemplateSpecs.
  20. type PodTemplateSpecTester struct {
  21. t *testing.T
  22. template *v1.PodTemplateSpec
  23. }
  24. // NewPodTemplateSpecTester creates a new tester to test the given PodTemplateSpec
  25. func NewPodTemplateSpecTester(t *testing.T, template *v1.PodTemplateSpec) *PodTemplateSpecTester {
  26. return &PodTemplateSpecTester{t: t, template: template}
  27. }
  28. // AssertLabelsContainRookRequirements asserts that the PodTemplateSpec under test contains labels
  29. // which all Rook pods should have.
  30. func (pt *PodTemplateSpecTester) AssertLabelsContainRookRequirements(appName string) {
  31. AssertLabelsContainRookRequirements(pt.t, pt.template.ObjectMeta.Labels, appName)
  32. }
  33. // RunFullSuite runs all assertion tests for the PodTemplateSpec under test and its sub-resources.
  34. func (pt *PodTemplateSpecTester) RunFullSuite(
  35. appName string,
  36. resourceExpectations ResourceLimitExpectations,
  37. ) {
  38. pt.AssertLabelsContainRookRequirements(appName)
  39. pt.Spec().RunFullSuite(resourceExpectations)
  40. }