subvolumegroup_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 client
  14. import (
  15. "testing"
  16. cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
  17. "github.com/stretchr/testify/assert"
  18. )
  19. func TestValidatePinningValues(t *testing.T) {
  20. // set Distributed correctly
  21. var testDistributedData cephv1.CephFilesystemSubVolumeGroupSpecPinning
  22. var testDistributedValue = 1
  23. testDistributedData.Distributed = &testDistributedValue
  24. err := validatePinningValues(testDistributedData)
  25. assert.NoError(t, err)
  26. // set Distributed wrongly
  27. var testDistributedData1 cephv1.CephFilesystemSubVolumeGroupSpecPinning
  28. var testDistributedValue1 = 5
  29. testDistributedData1.Distributed = &testDistributedValue1
  30. err = validatePinningValues(testDistributedData1)
  31. assert.Error(t, err)
  32. // set Random correctly
  33. var testRandomData cephv1.CephFilesystemSubVolumeGroupSpecPinning
  34. var testRandomdValue = 1.0
  35. testRandomData.Random = &testRandomdValue
  36. err = validatePinningValues(testRandomData)
  37. assert.NoError(t, err)
  38. // set Random wrongly
  39. var testRandomData1 cephv1.CephFilesystemSubVolumeGroupSpecPinning
  40. var testRandomdValue1 = 5.0
  41. testRandomData1.Random = &testRandomdValue1
  42. err = validatePinningValues(testRandomData1)
  43. assert.Error(t, err)
  44. // set export correctly
  45. var testExportData cephv1.CephFilesystemSubVolumeGroupSpecPinning
  46. var testExportValue = 1
  47. testExportData.Distributed = &testExportValue
  48. err = validatePinningValues(testExportData)
  49. assert.NoError(t, err)
  50. // set export wrongly
  51. var testExportData1 cephv1.CephFilesystemSubVolumeGroupSpecPinning
  52. var testExportValue1 = 500
  53. testExportData1.Distributed = &testExportValue1
  54. err = validatePinningValues(testExportData1)
  55. assert.Error(t, err)
  56. // more than one set at a time, error
  57. var testData cephv1.CephFilesystemSubVolumeGroupSpecPinning
  58. var testValue = 1
  59. testData.Distributed = &testValue
  60. testData.Export = &testValue
  61. err = validatePinningValues(testData)
  62. assert.Error(t, err)
  63. // nothing is set, noerror
  64. var testData1 cephv1.CephFilesystemSubVolumeGroupSpecPinning
  65. err = validatePinningValues(testData1)
  66. assert.NoError(t, err)
  67. }