(t *testing.T)
| 50 | } |
| 51 | |
| 52 | func TestLogRotation(t *testing.T) { |
| 53 | t.Parallel() |
| 54 | |
| 55 | const Day = 24 * time.Hour |
| 56 | |
| 57 | random := func(low, high time.Duration) time.Duration { |
| 58 | return low + rand.N(high-low) |
| 59 | } |
| 60 | |
| 61 | for _, tt := range []struct { |
| 62 | duration time.Duration |
| 63 | prefix string |
| 64 | suffix string |
| 65 | expected map[string]string |
| 66 | }{ |
| 67 | // Small duration becomes one hour split into minutes |
| 68 | {duration: random(1, time.Hour), |
| 69 | expected: map[string]string{ |
| 70 | "log_filename": "%M", // two-digit minute [00, 59] |
| 71 | "log_rotation_age": "1min", // × 1 minute = 1 hour |
| 72 | "log_rotation_size": "0", |
| 73 | "log_truncate_on_rotation": "on", |
| 74 | }}, |
| 75 | |
| 76 | // More than an hour becomes one day split into hours |
| 77 | {duration: random(90*time.Minute, 24*time.Hour), |
| 78 | expected: map[string]string{ |
| 79 | "log_filename": "%H", // two-digit hour [00,23] |
| 80 | "log_rotation_age": "1h", // × 1 hour = 1 day |
| 81 | "log_rotation_size": "0", |
| 82 | "log_truncate_on_rotation": "on", |
| 83 | }}, |
| 84 | |
| 85 | // More than one day becomes one week split into days |
| 86 | {duration: random(3*Day, 7*Day), |
| 87 | expected: map[string]string{ |
| 88 | "log_filename": "%a", // locale weekday name |
| 89 | "log_rotation_age": "1d", // × 1 day = 1 week |
| 90 | "log_rotation_size": "0", |
| 91 | "log_truncate_on_rotation": "on", |
| 92 | }}, |
| 93 | |
| 94 | // More than one week becomes one month split into days |
| 95 | {duration: random(11*Day, 25*Day), |
| 96 | expected: map[string]string{ |
| 97 | "log_filename": "%d", // two-digit day of the month [01, 31] |
| 98 | "log_rotation_age": "1d", // × 1 day = 1 month |
| 99 | "log_rotation_size": "0", |
| 100 | "log_truncate_on_rotation": "on", |
| 101 | }}, |
| 102 | |
| 103 | // More than one month becomes one year split into days |
| 104 | {duration: random(70*Day, 300*Day), |
| 105 | expected: map[string]string{ |
| 106 | "log_filename": "%j", // three-digit day of the year [001, 366] |
| 107 | "log_rotation_age": "1d", // × 1 day = 1 year |
| 108 | "log_rotation_size": "0", |
| 109 | "log_truncate_on_rotation": "on", |
nothing calls this directly
no test coverage detected