(t *testing.T)
| 265 | } |
| 266 | |
| 267 | func TestParseDuration(t *testing.T) { |
| 268 | tests := []struct { |
| 269 | name string |
| 270 | input string |
| 271 | want time.Duration |
| 272 | wantErr bool |
| 273 | }{ |
| 274 | { |
| 275 | name: "days supported", |
| 276 | input: "7d", |
| 277 | want: 7 * 24 * time.Hour, |
| 278 | wantErr: false, |
| 279 | }, |
| 280 | { |
| 281 | name: "hours", |
| 282 | input: "24h", |
| 283 | want: 24 * time.Hour, |
| 284 | wantErr: false, |
| 285 | }, |
| 286 | { |
| 287 | name: "minutes", |
| 288 | input: "30m", |
| 289 | want: 30 * time.Minute, |
| 290 | wantErr: false, |
| 291 | }, |
| 292 | { |
| 293 | name: "seconds", |
| 294 | input: "60s", |
| 295 | want: 60 * time.Second, |
| 296 | wantErr: false, |
| 297 | }, |
| 298 | { |
| 299 | name: "milliseconds", |
| 300 | input: "500ms", |
| 301 | want: 500 * time.Millisecond, |
| 302 | wantErr: false, |
| 303 | }, |
| 304 | { |
| 305 | name: "invalid suffix", |
| 306 | input: "10x", |
| 307 | wantErr: true, |
| 308 | }, |
| 309 | { |
| 310 | name: "too short", |
| 311 | input: "s", |
| 312 | wantErr: true, |
| 313 | }, |
| 314 | } |
| 315 | |
| 316 | for _, test := range tests { |
| 317 | t.Run(test.name, func(t *testing.T) { |
| 318 | got, err := parseDuration(test.input) |
| 319 | if (err != nil) != test.wantErr { |
| 320 | t.Fatalf("parseDuration(%q) error = %v, wantErr = %v", test.input, err, test.wantErr) |
| 321 | } |
| 322 | if err == nil && got != test.want { |
| 323 | t.Errorf("parseDuration(%q) = %v, want %v", test.input, got, test.want) |
| 324 | } |
nothing calls this directly
no test coverage detected