MCPcopy
hub / github.com/minio/minio-go / TestIsValidExpiry

Function TestIsValidExpiry

utils_test.go:269–301  ·  view source on GitHub ↗

Tests validate the expiry time validator.

(t *testing.T)

Source from the content-addressed store, hash-verified

267
268// Tests validate the expiry time validator.
269func TestIsValidExpiry(t *testing.T) {
270 testCases := []struct {
271 // Input.
272 duration time.Duration
273 // Expected result.
274 err error
275 // Flag to indicate whether the test should pass.
276 shouldPass bool
277 }{
278 {100 * time.Millisecond, errInvalidArgument("Expires cannot be lesser than 1 second."), false},
279 {604801 * time.Second, errInvalidArgument("Expires cannot be greater than 7 days."), false},
280 {0 * time.Second, errInvalidArgument("Expires cannot be lesser than 1 second."), false},
281 {1 * time.Second, nil, true},
282 {10000 * time.Second, nil, true},
283 {999 * time.Second, nil, true},
284 }
285
286 for i, testCase := range testCases {
287 err := isValidExpiry(testCase.duration)
288 if err != nil && testCase.shouldPass {
289 t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s", i+1, err.Error())
290 }
291 if err == nil && !testCase.shouldPass {
292 t.Errorf("Test %d: Expected to fail with <ERROR> \"%s\", but passed instead", i+1, testCase.err.Error())
293 }
294 // Failed as expected, but does it fail for the expected reason.
295 if err != nil && !testCase.shouldPass {
296 if err.Error() != testCase.err.Error() {
297 t.Errorf("Test %d: Expected to fail with error \"%s\", but instead failed with error \"%s\" instead", i+1, testCase.err.Error(), err.Error())
298 }
299 }
300 }
301}
302
303// Tests validate the bucket name validator.
304func TestIsValidBucketName(t *testing.T) {

Callers

nothing calls this directly

Calls 3

errInvalidArgumentFunction · 0.85
isValidExpiryFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected