(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestCronitorIgnoreComment(t *testing.T) { |
| 12 | // Create a temporary crontab with cronitor: ignore comment |
| 13 | crontabContent := `# cronitor: ignore |
| 14 | 0 * * * * echo "this job should be ignored" |
| 15 | |
| 16 | # Name: Test Job |
| 17 | 0 * * * * echo "this job should not be ignored"` |
| 18 | |
| 19 | // Create a crontab object |
| 20 | crontab := &Crontab{ |
| 21 | IsUserCrontab: true, |
| 22 | Filename: "test", |
| 23 | } |
| 24 | |
| 25 | // Mock the load function by creating lines directly |
| 26 | lines := strings.Split(crontabContent, "\n") |
| 27 | |
| 28 | // Parse the content |
| 29 | var name string |
| 30 | var ignored bool |
| 31 | |
| 32 | for lineNumber, fullLine := range lines { |
| 33 | fullLine = strings.TrimSpace(fullLine) |
| 34 | |
| 35 | // Skip empty lines |
| 36 | if fullLine == "" { |
| 37 | continue |
| 38 | } |
| 39 | |
| 40 | // Check for special Name: comment |
| 41 | if nameMatch := regexp.MustCompile(`^#\s*Name:\s*(.+)$`).FindStringSubmatch(fullLine); nameMatch != nil { |
| 42 | name = strings.TrimSpace(nameMatch[1]) |
| 43 | continue |
| 44 | } |
| 45 | |
| 46 | // Check for special cronitor: ignore comment |
| 47 | if ignoreMatch := regexp.MustCompile(`^#\s*cronitor:\s*ignore\s*$`).FindStringSubmatch(fullLine); ignoreMatch != nil { |
| 48 | ignored = true |
| 49 | continue |
| 50 | } |
| 51 | |
| 52 | // Skip other comments |
| 53 | if strings.HasPrefix(fullLine, "#") { |
| 54 | continue |
| 55 | } |
| 56 | |
| 57 | // Parse cron line |
| 58 | splitLine := strings.Fields(fullLine) |
| 59 | if len(splitLine) >= 6 { |
| 60 | cronExpression := strings.Join(splitLine[0:5], " ") |
| 61 | command := splitLine[5:] |
| 62 | |
| 63 | line := Line{ |
| 64 | IsJob: true, |
| 65 | Name: name, |
| 66 | CronExpression: cronExpression, |
| 67 | CommandToRun: strings.Join(command, " "), |
| 68 | FullLine: fullLine, |
nothing calls this directly
no test coverage detected