(t *testing.T)
| 168 | } |
| 169 | |
| 170 | func TestRetryWatcher(t *testing.T) { |
| 171 | tt := []struct { |
| 172 | name string |
| 173 | initialRV string |
| 174 | watchClient cache.Watcher |
| 175 | watchCount uint32 |
| 176 | expected []watch.Event |
| 177 | }{ |
| 178 | { |
| 179 | name: "recovers if watchClient returns error", |
| 180 | initialRV: "1", |
| 181 | watchClient: &cache.ListWatch{ |
| 182 | WatchFunc: func() func(options metav1.ListOptions) (watch.Interface, error) { |
| 183 | firstRun := true |
| 184 | return func(options metav1.ListOptions) (watch.Interface, error) { |
| 185 | if firstRun { |
| 186 | firstRun = false |
| 187 | return nil, fmt.Errorf("test error") |
| 188 | } |
| 189 | |
| 190 | return watch.NewProxyWatcher(arrayToChannel(fromRV(options.ResourceVersion, []watch.Event{ |
| 191 | makeTestEvent(2), |
| 192 | }))), nil |
| 193 | } |
| 194 | }(), |
| 195 | }, |
| 196 | watchCount: 2, |
| 197 | expected: []watch.Event{ |
| 198 | makeTestEvent(2), |
| 199 | }, |
| 200 | }, |
| 201 | { |
| 202 | name: "recovers if watchClient returns nil watcher", |
| 203 | initialRV: "1", |
| 204 | watchClient: &cache.ListWatch{ |
| 205 | WatchFunc: func() func(options metav1.ListOptions) (watch.Interface, error) { |
| 206 | firstRun := true |
| 207 | return func(options metav1.ListOptions) (watch.Interface, error) { |
| 208 | if firstRun { |
| 209 | firstRun = false |
| 210 | return nil, nil |
| 211 | } |
| 212 | |
| 213 | return watch.NewProxyWatcher(arrayToChannel(fromRV(options.ResourceVersion, []watch.Event{ |
| 214 | makeTestEvent(2), |
| 215 | }))), nil |
| 216 | } |
| 217 | }(), |
| 218 | }, |
| 219 | watchCount: 2, |
| 220 | expected: []watch.Event{ |
| 221 | makeTestEvent(2), |
| 222 | }, |
| 223 | }, |
| 224 | { |
| 225 | name: "works with empty initialRV", |
| 226 | initialRV: "1", |
| 227 | watchClient: &cache.ListWatch{ |
nothing calls this directly
no test coverage detected