|
8 | 8 | "testing" |
9 | 9 |
|
10 | 10 | "gotest.tools/v3/assert" |
| 11 | + |
| 12 | + "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1" |
11 | 13 | ) |
12 | 14 |
|
13 | 15 | func TestConfigToYAML(t *testing.T) { |
@@ -62,110 +64,67 @@ service: |
62 | 64 | }) |
63 | 65 | } |
64 | 66 |
|
65 | | -func TestParseRetentionPeriodForLogrotate(t *testing.T) { |
66 | | - t.Run("SuccessfulParse", func(t *testing.T) { |
67 | | - for _, tt := range []struct { |
68 | | - retentionPeriod string |
69 | | - retentionPeriodMap map[string]string |
70 | | - }{ |
71 | | - { |
72 | | - retentionPeriod: "12h", |
73 | | - retentionPeriodMap: map[string]string{ |
74 | | - "number": "12", |
75 | | - "interval": "", |
76 | | - }, |
77 | | - }, |
78 | | - { |
79 | | - retentionPeriod: "24hr", |
80 | | - retentionPeriodMap: map[string]string{ |
81 | | - "number": "24", |
82 | | - "interval": "", |
83 | | - }, |
84 | | - }, |
85 | | - { |
86 | | - retentionPeriod: "36hour", |
87 | | - retentionPeriodMap: map[string]string{ |
88 | | - "number": "36", |
89 | | - "interval": "", |
90 | | - }, |
91 | | - }, |
92 | | - { |
93 | | - retentionPeriod: "3d", |
94 | | - retentionPeriodMap: map[string]string{ |
95 | | - "number": "3", |
96 | | - "interval": "daily", |
97 | | - }, |
98 | | - }, |
99 | | - { |
100 | | - retentionPeriod: "365day", |
101 | | - retentionPeriodMap: map[string]string{ |
102 | | - "number": "365", |
103 | | - "interval": "daily", |
104 | | - }, |
105 | | - }, |
106 | | - { |
107 | | - retentionPeriod: "1w", |
108 | | - retentionPeriodMap: map[string]string{ |
109 | | - "number": "1", |
110 | | - "interval": "weekly", |
111 | | - }, |
112 | | - }, |
113 | | - { |
114 | | - retentionPeriod: "4wk", |
115 | | - retentionPeriodMap: map[string]string{ |
116 | | - "number": "4", |
117 | | - "interval": "weekly", |
118 | | - }, |
119 | | - }, |
120 | | - { |
121 | | - retentionPeriod: "52week", |
122 | | - retentionPeriodMap: map[string]string{ |
123 | | - "number": "52", |
124 | | - "interval": "weekly", |
125 | | - }, |
126 | | - }, |
127 | | - } { |
128 | | - t.Run(tt.retentionPeriod, func(t *testing.T) { |
129 | | - rpm, err := parseRetentionPeriodForLogrotate(tt.retentionPeriod) |
130 | | - assert.NilError(t, err) |
131 | | - assert.Equal(t, tt.retentionPeriodMap["number"], rpm["number"]) |
132 | | - }) |
133 | | - } |
134 | | - }) |
| 67 | +// TODO: write this test after rebasing on new retention API changes. |
| 68 | +// func TestGenerateLogrotateConfig(t *testing.T) { |
135 | 69 |
|
136 | | - t.Run("UnsuccessfulParse", func(t *testing.T) { |
137 | | - for _, tt := range []struct { |
138 | | - retentionPeriod string |
139 | | - errMessage string |
140 | | - }{ |
141 | | - { |
142 | | - retentionPeriod: "", |
143 | | - errMessage: "invalid retentionPeriod; must be number of hours, days, or weeks", |
144 | | - }, |
145 | | - { |
146 | | - retentionPeriod: "asdf", |
147 | | - errMessage: "invalid retentionPeriod; must be number of hours, days, or weeks", |
148 | | - }, |
149 | | - { |
150 | | - retentionPeriod: "1234", |
151 | | - errMessage: "invalid retentionPeriod; must be number of hours, days, or weeks", |
152 | | - }, |
153 | | - { |
154 | | - retentionPeriod: "d2", |
155 | | - errMessage: "invalid retentionPeriod; must be number of hours, days, or weeks", |
156 | | - }, |
157 | | - { |
158 | | - retentionPeriod: "1000z", |
159 | | - errMessage: "invalid retentionPeriod; z is not a valid unit", |
160 | | - }, |
161 | | - } { |
162 | | - t.Run(tt.retentionPeriod, func(t *testing.T) { |
163 | | - rpm, err := parseRetentionPeriodForLogrotate(tt.retentionPeriod) |
164 | | - assert.Assert(t, rpm == nil) |
165 | | - assert.Assert(t, err != nil) |
166 | | - assert.ErrorContains(t, err, tt.errMessage) |
167 | | - // assert.Equal(t, tt.retentionPeriodMap["number"], rpm["number"]) |
168 | | - }) |
169 | | - } |
170 | | - }) |
| 70 | +// } |
| 71 | + |
| 72 | +// FIXME: This test is currently broken. Fix after rebasing on new |
| 73 | +// retention API changes. |
| 74 | +func TestParseDurationForLogrotate(t *testing.T) { |
| 75 | + for _, tt := range []struct { |
| 76 | + retentionPeriod string |
| 77 | + number int |
| 78 | + interval string |
| 79 | + }{ |
| 80 | + { |
| 81 | + retentionPeriod: "12h", |
| 82 | + number: 12, |
| 83 | + interval: "hourly", |
| 84 | + }, |
| 85 | + { |
| 86 | + retentionPeriod: "24hr", |
| 87 | + number: 1, |
| 88 | + interval: "daily", |
| 89 | + }, |
| 90 | + { |
| 91 | + retentionPeriod: "36hour", |
| 92 | + number: 2, |
| 93 | + interval: "daily", |
| 94 | + }, |
| 95 | + { |
| 96 | + retentionPeriod: "3d", |
| 97 | + number: 3, |
| 98 | + interval: "daily", |
| 99 | + }, |
| 100 | + { |
| 101 | + retentionPeriod: "365day", |
| 102 | + number: 365, |
| 103 | + interval: "daily", |
| 104 | + }, |
| 105 | + { |
| 106 | + retentionPeriod: "1w", |
| 107 | + number: 7, |
| 108 | + interval: "daily", |
| 109 | + }, |
| 110 | + { |
| 111 | + retentionPeriod: "4wk", |
| 112 | + number: 28, |
| 113 | + interval: "daily", |
| 114 | + }, |
| 115 | + { |
| 116 | + retentionPeriod: "52week", |
| 117 | + number: 364, |
| 118 | + interval: "daily", |
| 119 | + }, |
| 120 | + } { |
| 121 | + t.Run(tt.retentionPeriod, func(t *testing.T) { |
| 122 | + var duration *v1beta1.Duration |
| 123 | + err := duration.UnmarshalJSON([]byte(tt.retentionPeriod)) |
| 124 | + assert.NilError(t, err) |
| 125 | + number, interval := parseDurationForLogrotate(duration) |
| 126 | + assert.Equal(t, tt.number, number) |
| 127 | + assert.Equal(t, tt.interval, interval) |
| 128 | + }) |
| 129 | + } |
171 | 130 | } |
0 commit comments