MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / TestCronitorIgnoreComment

Function TestCronitorIgnoreComment

lib/crontab_test.go:11–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestCronitorIgnoreComment(t *testing.T) {
12 // Create a temporary crontab with cronitor: ignore comment
13 crontabContent := `# cronitor: ignore
140 * * * * echo "this job should be ignored"
15
16# Name: Test Job
170 * * * * 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,

Callers

nothing calls this directly

Calls 2

lightweightCopyMethod · 0.95
WriteMethod · 0.45

Tested by

no test coverage detected