priorityclasses_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 v1
  14. import (
  15. "encoding/json"
  16. "testing"
  17. "github.com/stretchr/testify/assert"
  18. "k8s.io/apimachinery/pkg/util/yaml"
  19. )
  20. func TestPriorityClassNamesSpec(t *testing.T) {
  21. specYaml := []byte(`
  22. all: all-class
  23. mgr: mgr-class
  24. mon: mon-class
  25. osd: osd-class
  26. crashcollector: crashcollector-class
  27. `)
  28. // convert the raw spec yaml into JSON
  29. rawJSON, err := yaml.ToJSON(specYaml)
  30. assert.Nil(t, err)
  31. // unmarshal the JSON into a strongly typed annotations spec object
  32. var priorityClassNames PriorityClassNamesSpec
  33. err = json.Unmarshal(rawJSON, &priorityClassNames)
  34. assert.Nil(t, err)
  35. // the unmarshalled priority class names spec should equal the expected spec below
  36. expected := PriorityClassNamesSpec{
  37. "all": "all-class",
  38. "mgr": "mgr-class",
  39. "mon": "mon-class",
  40. "osd": "osd-class",
  41. "crashcollector": "crashcollector-class",
  42. }
  43. assert.Equal(t, expected, priorityClassNames)
  44. }
  45. func TestPriorityClassNamesDefaultToAll(t *testing.T) {
  46. priorityClassNames := PriorityClassNamesSpec{
  47. "all": "all-class",
  48. "mon": "mon-class",
  49. }
  50. assert.Equal(t, "all-class", priorityClassNames.All())
  51. }