pool_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright 2020 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. "testing"
  16. "github.com/stretchr/testify/assert"
  17. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  18. )
  19. func TestValidatePoolSpec(t *testing.T) {
  20. p := &CephBlockPool{
  21. ObjectMeta: metav1.ObjectMeta{
  22. Name: "ec-pool",
  23. },
  24. Spec: NamedBlockPoolSpec{
  25. PoolSpec: PoolSpec{
  26. ErasureCoded: ErasureCodedSpec{
  27. CodingChunks: 1,
  28. DataChunks: 2,
  29. },
  30. },
  31. },
  32. }
  33. err := validatePoolSpec(p.ToNamedPoolSpec())
  34. assert.NoError(t, err)
  35. p.Spec.ErasureCoded.DataChunks = 1
  36. err = validatePoolSpec(p.ToNamedPoolSpec())
  37. assert.Error(t, err)
  38. }
  39. func TestMirroringSpec_SnapshotSchedulesEnabled(t *testing.T) {
  40. type fields struct {
  41. Enabled bool
  42. Mode string
  43. SnapshotSchedules []SnapshotScheduleSpec
  44. }
  45. tests := []struct {
  46. name string
  47. fields fields
  48. want bool
  49. }{
  50. {"disabled", fields{Enabled: true, Mode: "pool", SnapshotSchedules: []SnapshotScheduleSpec{}}, false},
  51. {"enabled", fields{Enabled: true, Mode: "pool", SnapshotSchedules: []SnapshotScheduleSpec{{Interval: "2d"}}}, true},
  52. }
  53. for _, tt := range tests {
  54. t.Run(tt.name, func(t *testing.T) {
  55. p := &MirroringSpec{
  56. Enabled: tt.fields.Enabled,
  57. Mode: tt.fields.Mode,
  58. SnapshotSchedules: tt.fields.SnapshotSchedules,
  59. }
  60. if got := p.SnapshotSchedulesEnabled(); got != tt.want {
  61. t.Errorf("MirroringSpec.SnapshotSchedulesEnabled() = %v, want %v", got, tt.want)
  62. }
  63. })
  64. }
  65. }