| 1 | package mainscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/ |
| 2 | |
| 3 | import ( |
| 4 | "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/" |
| 5 | "ioscip-go gomod github.com/golang/go/src go1.25.0 io/" |
| 6 | "io/fsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/" |
| 7 | "logscip-go gomod github.com/golang/go/src go1.25.0 log/" |
| 8 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 9 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 10 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 11 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 12 | "timescip-go gomod github.com/golang/go/src go1.25.0 time/" |
| 13 | |
| 14 | "launchpad.net/email-reminder/internal/configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/" |
| 15 | "launchpad.net/email-reminder/internal/eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/" |
| 16 | "launchpad.net/email-reminder/internal/utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/" |
| 17 | ) |
| 18 | |
| 19 | var cfgscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/cfg. = configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.Configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#{ |
| 20 | MaxRecipientsPerEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxRecipientsPerEvent.: 10000, |
| 21 | } |
| 22 | |
| 23 | var defaultRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/defaultRecipient. = utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#{Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#Email.: "[email protected]"} |
| 24 | |
| 25 | // Hide any log output that processEvent may trigger |
| 26 | func discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 27 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 28 | original := logscip-go gomod github.com/golang/go/src go1.25.0 log/.Writerscip-go gomod github.com/golang/go/src go1.25.0 log/Writer().() |
| 29 | logscip-go gomod github.com/golang/go/src go1.25.0 log/.SetOutputscip-go gomod github.com/golang/go/src go1.25.0 log/SetOutput().(ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Discardscip-go gomod github.com/golang/go/src go1.25.0 io/Discard.) |
| 30 | t.Cleanupscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Cleanup().(func() { |
| 31 | logscip-go gomod github.com/golang/go/src go1.25.0 log/.SetOutputscip-go gomod github.com/golang/go/src go1.25.0 log/SetOutput().(original) |
| 32 | }) |
| 33 | } |
| 34 | |
| 35 | type mockNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier# struct { |
| 36 | sendFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendFunc. func(body, subject string, recipients []utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) []error |
| 37 | sendDebugFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendDebugFunc. func(now timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time#, event eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#, when string, failures []error, defaultRecipient utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) |
| 38 | } |
| 39 | |
| 40 | func (m *mockNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#) Sendscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#Send().(body, subject string, recipients []utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) []error { |
| 41 | if m.sendFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendFunc. != nil { |
| 42 | return m.sendFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendFunc.(body, subject, recipients) |
| 43 | } |
| 44 | return nil |
| 45 | } |
| 46 | |
| 47 | func (m *mockNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#) SendDebugscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#SendDebug().(now timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time#, event eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#, when string, failures []error, defaultRecipient utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) { |
| 48 | if m.sendDebugFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendDebugFunc. != nil { |
| 49 | m.sendDebugFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendDebugFunc.(now, event, when, failures, defaultRecipient) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | func TestProcessEventSkipsInvalidEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/TestProcessEventSkipsInvalidEvent().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 54 | discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t) |
| 55 | |
| 56 | now := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().() |
| 57 | event := eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#{Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Type.: eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.EventTypeBirthdayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/EventTypeBirthday.} |
| 58 | |
| 59 | called := false |
| 60 | notifier := &mockNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#{ |
| 61 | sendFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendFunc.: func(body, subject string, recipients []utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) []error { |
| 62 | called = true |
| 63 | return nil |
| 64 | }, |
| 65 | } |
| 66 | processEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/processEvent().(now, event, defaultRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/defaultRecipient., cfgscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/cfg., notifier) |
| 67 | |
| 68 | if called { |
| 69 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected invalid event to be skipped") |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func TestProcessEventSendsReminderWhenOccurringscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/TestProcessEventSendsReminderWhenOccurring().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 74 | discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t) |
| 75 | |
| 76 | now := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Datescip-go gomod github.com/golang/go/src go1.25.0 time/Date().(2024, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., 10, 9, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.25.0 time/.UTCscip-go gomod github.com/golang/go/src go1.25.0 time/UTC.) |
| 77 | event := eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#{ |
| 78 | Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Type.: eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.EventTypeBirthdayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/EventTypeBirthday., |
| 79 | Namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Name.: "Alice", |
| 80 | Monthscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Month.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., |
| 81 | Dayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Day.: 10, |
| 82 | Remindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Reminders.: []eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Reminderscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Reminder#{{Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Reminder#Type.: eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.ReminderTypeSameDayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/ReminderTypeSameDay.}}, |
| 83 | } |
| 84 | |
| 85 | sendCount := 0 |
| 86 | debugCount := 0 |
| 87 | notifier := &mockNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#{ |
| 88 | sendFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendFunc.: func(body, subject string, recipients []utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) []error { |
| 89 | sendCount++ |
| 90 | if body == "" { |
| 91 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected body to be populated") |
| 92 | } |
| 93 | if subject == "" { |
| 94 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected subject to be populated") |
| 95 | } |
| 96 | if len(recipients) == 0 { |
| 97 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected at least one recipient") |
| 98 | } |
| 99 | return nil |
| 100 | }, |
| 101 | sendDebugFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendDebugFunc.: func(now timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time#, event eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#, when string, failures []error, defaultRecipient utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) { |
| 102 | debugCount++ |
| 103 | }, |
| 104 | } |
| 105 | processEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/processEvent().(now, event, defaultRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/defaultRecipient., cfgscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/cfg., notifier) |
| 106 | |
| 107 | if sendCount != 1 { |
| 108 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected exactly one reminder to be sent, got %d", sendCount) |
| 109 | } |
| 110 | if debugCount != 0 { |
| 111 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected no debug email to be sent") |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | func TestProcessEventSendsDebugOnFailurescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/TestProcessEventSendsDebugOnFailure().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 116 | discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t) |
| 117 | |
| 118 | now := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Datescip-go gomod github.com/golang/go/src go1.25.0 time/Date().(2024, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., 10, 9, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.25.0 time/.UTCscip-go gomod github.com/golang/go/src go1.25.0 time/UTC.) |
| 119 | event := eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#{ |
| 120 | Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Type.: eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.EventTypeBirthdayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/EventTypeBirthday., |
| 121 | Namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Name.: "Alice", |
| 122 | Monthscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Month.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., |
| 123 | Dayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Day.: 10, |
| 124 | Remindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Reminders.: []eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Reminderscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Reminder#{{Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Reminder#Type.: eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.ReminderTypeSameDayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/ReminderTypeSameDay.}}, |
| 125 | } |
| 126 | |
| 127 | sendCount := 0 |
| 128 | debugCount := 0 |
| 129 | notifier := &mockNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#{ |
| 130 | sendFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendFunc.: func(body, subject string, recipients []utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) []error { |
| 131 | sendCount++ |
| 132 | return []error{errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("boom")} |
| 133 | }, |
| 134 | sendDebugFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendDebugFunc.: func(now timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time#, event eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#, when string, failures []error, defaultRecipient utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) { |
| 135 | debugCount++ |
| 136 | if len(failures) != 1 { |
| 137 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected to receive the send errors") |
| 138 | } |
| 139 | }, |
| 140 | } |
| 141 | processEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/processEvent().(now, event, defaultRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/defaultRecipient., cfgscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/cfg., notifier) |
| 142 | |
| 143 | if sendCount != 1 { |
| 144 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected a send attempt") |
| 145 | } |
| 146 | if debugCount != 1 { |
| 147 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected a debug email to be triggered") |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | func TestProcessEventSkipsWhenNotOccurringscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/TestProcessEventSkipsWhenNotOccurring().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 152 | discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t) |
| 153 | |
| 154 | now := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Datescip-go gomod github.com/golang/go/src go1.25.0 time/Date().(2024, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., 5, 9, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.25.0 time/.UTCscip-go gomod github.com/golang/go/src go1.25.0 time/UTC.) |
| 155 | event := eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#{ |
| 156 | Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Type.: eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.EventTypeBirthdayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/EventTypeBirthday., |
| 157 | Namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Name.: "Alice", |
| 158 | Monthscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Month.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., |
| 159 | Dayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Day.: 10, |
| 160 | Remindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Reminders.: []eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Reminderscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Reminder#{{Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Reminder#Type.: eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.ReminderTypeSameDayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/ReminderTypeSameDay.}}, |
| 161 | } |
| 162 | |
| 163 | sendCount := 0 |
| 164 | notifier := &mockNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#{ |
| 165 | sendFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendFunc.: func(body, subject string, recipients []utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) []error { |
| 166 | sendCount++ |
| 167 | return nil |
| 168 | }, |
| 169 | } |
| 170 | processEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/processEvent().(now, event, defaultRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/defaultRecipient., cfgscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/cfg., notifier) |
| 171 | |
| 172 | if sendCount != 0 { |
| 173 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected no reminder to be sent, got %d", sendCount) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | func TestProcessEventHandlesMultipleRemindersAndRecipientsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/TestProcessEventHandlesMultipleRemindersAndRecipients().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 178 | discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t) |
| 179 | |
| 180 | now := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Datescip-go gomod github.com/golang/go/src go1.25.0 time/Date().(2024, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., 7, 9, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.25.0 time/.UTCscip-go gomod github.com/golang/go/src go1.25.0 time/UTC.) |
| 181 | event := eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#{ |
| 182 | Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Type.: eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.EventTypeBirthdayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/EventTypeBirthday., |
| 183 | Namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Name.: "Alice", |
| 184 | Monthscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Month.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., |
| 185 | Dayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Day.: 10, |
| 186 | Remindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Reminders.: []eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Reminderscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Reminder#{ |
| 187 | {Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Reminder#Type.: eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.ReminderTypeDaysBeforescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/ReminderTypeDaysBefore., Daysscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Reminder#Days.: 3}, |
| 188 | {Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Reminder#Type.: eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.ReminderTypeSameDayscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/ReminderTypeSameDay.}, |
| 189 | }, |
| 190 | Recipientsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Recipients.: []eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Recipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#{ |
| 191 | {Namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#Name.: "Bob", Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#Email.: "[email protected]"}, |
| 192 | {Namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#Name.: "Carol", Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#Email.: "[email protected]"}, |
| 193 | }, |
| 194 | } |
| 195 | |
| 196 | sendCount := 0 |
| 197 | debugCount := 0 |
| 198 | var gotBody, gotSubject string |
| 199 | var gotRecipientsCount int |
| 200 | notifier := &mockNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#{ |
| 201 | sendFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendFunc.: func(body, subject string, recipients []utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) []error { |
| 202 | sendCount++ |
| 203 | gotBody = body |
| 204 | gotSubject = subject |
| 205 | gotRecipientsCount = len(recipients) |
| 206 | return nil |
| 207 | }, |
| 208 | sendDebugFuncscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockNotifier#sendDebugFunc.: func(now timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time#, event eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#, when string, failures []error, defaultRecipient utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) { |
| 209 | debugCount++ |
| 210 | }, |
| 211 | } |
| 212 | processEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/processEvent().(now, event, defaultRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/defaultRecipient., cfgscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/cfg., notifier) |
| 213 | |
| 214 | if sendCount != 1 { |
| 215 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected exactly one reminder to be sent, got %d", sendCount) |
| 216 | } |
| 217 | if debugCount != 0 { |
| 218 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected no debug email to be sent, got %d", debugCount) |
| 219 | } |
| 220 | if gotSubject == "" { |
| 221 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected subject to be populated") |
| 222 | } |
| 223 | if !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(gotBody, "in 3 days") { |
| 224 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected body to reference the first matching reminder, got %q", gotBody) |
| 225 | } |
| 226 | if gotRecipientsCount != 2 { |
| 227 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected two recipients, got %d", gotRecipientsCount) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // Minimal testing mock of fs.DirEntry |
| 232 | type mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry# struct { |
| 233 | namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#name. string |
| 234 | isDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#isDir. bool |
| 235 | } |
| 236 | |
| 237 | func (m mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#) Namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#Name().() string { return m.namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#name. } |
| 238 | func (m mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#) IsDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#IsDir().() bool { return m.isDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#isDir. } |
| 239 | func (m mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#) Typescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#Type().() fsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/.FileModescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileMode# { return 0 } |
| 240 | func (m mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#) Infoscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#Info().() (fsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/.FileInfoscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#, error) { return nil, nil } |
| 241 | |
| 242 | func TestShouldProcessPathscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/TestShouldProcessPath().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 243 | spoolDir := "/var/spool/reminders" |
| 244 | |
| 245 | tests := []struct { |
| 246 | name string |
| 247 | path string |
| 248 | dirEntry fsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/.DirEntryscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/DirEntry# |
| 249 | walkErr error |
| 250 | wantProcess bool |
| 251 | wantErr error |
| 252 | }{ |
| 253 | { |
| 254 | name: "regular file should be processed", |
| 255 | path: "/var/spool/reminders/user1", |
| 256 | dirEntry: mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#{namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#name.: "user1", isDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#isDir.: false}, |
| 257 | walkErr: nil, |
| 258 | wantProcess: true, |
| 259 | wantErr: nil, |
| 260 | }, |
| 261 | { |
| 262 | name: "hidden file should be skipped", |
| 263 | path: "/var/spool/reminders/.hidden", |
| 264 | dirEntry: mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#{namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#name.: ".hidden", isDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#isDir.: false}, |
| 265 | walkErr: nil, |
| 266 | wantProcess: false, |
| 267 | wantErr: nil, |
| 268 | }, |
| 269 | { |
| 270 | name: "hidden directory should be skipped with SkipDir", |
| 271 | path: "/var/spool/reminders/.cache", |
| 272 | dirEntry: mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#{namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#name.: ".cache", isDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#isDir.: true}, |
| 273 | walkErr: nil, |
| 274 | wantProcess: false, |
| 275 | wantErr: fsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/.SkipDirscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/SkipDir., |
| 276 | }, |
| 277 | { |
| 278 | name: "regular directory should not be processed but continue", |
| 279 | path: "/var/spool/reminders/subdir", |
| 280 | dirEntry: mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#{namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#name.: "subdir", isDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#isDir.: true}, |
| 281 | walkErr: nil, |
| 282 | wantProcess: false, |
| 283 | wantErr: nil, |
| 284 | }, |
| 285 | { |
| 286 | name: "error on spool dir should be fatal", |
| 287 | path: spoolDir, |
| 288 | dirEntry: mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#{namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#name.: "reminders", isDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#isDir.: true}, |
| 289 | walkErr: osscip-go gomod github.com/golang/go/src go1.25.0 os/.ErrPermissionscip-go gomod github.com/golang/go/src go1.25.0 os/ErrPermission., |
| 290 | wantProcess: false, |
| 291 | wantErr: osscip-go gomod github.com/golang/go/src go1.25.0 os/.ErrPermissionscip-go gomod github.com/golang/go/src go1.25.0 os/ErrPermission., |
| 292 | }, |
| 293 | { |
| 294 | name: "error on file should be skipped", |
| 295 | path: "/var/spool/reminders/badfile", |
| 296 | dirEntry: mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#{namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#name.: "badfile", isDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#isDir.: false}, |
| 297 | walkErr: osscip-go gomod github.com/golang/go/src go1.25.0 os/.ErrPermissionscip-go gomod github.com/golang/go/src go1.25.0 os/ErrPermission., |
| 298 | wantProcess: false, |
| 299 | wantErr: nil, |
| 300 | }, |
| 301 | { |
| 302 | name: "nested regular file should be processed", |
| 303 | path: "/var/spool/reminders/subdir/user 2", |
| 304 | dirEntry: mockDirEntryscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#{namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#name.: "user 2", isDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/mockDirEntry#isDir.: false}, |
| 305 | walkErr: nil, |
| 306 | wantProcess: true, |
| 307 | wantErr: nil, |
| 308 | }, |
| 309 | } |
| 310 | |
| 311 | for _, tt := range tests { |
| 312 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 313 | discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t) |
| 314 | conf := configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.Configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#{} |
| 315 | gotProcess, gotErr := shouldProcessPathscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/shouldProcessPath().(tt.path, tt.dirEntry, spoolDir, tt.walkErr, conf) |
| 316 | |
| 317 | if gotProcess != tt.wantProcess { |
| 318 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("process = %v, want %v", gotProcess, tt.wantProcess) |
| 319 | } |
| 320 | if tt.wantErr == nil { |
| 321 | if gotErr != nil { |
| 322 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("err = %v, want nil", gotErr) |
| 323 | } |
| 324 | } else if !errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(gotErr, tt.wantErr) { |
| 325 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("err = %v, wantErr %v", gotErr, tt.wantErr) |
| 326 | } |
| 327 | }) |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | func TestProcessSpooledFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/TestProcessSpooledFile().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 332 | discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t) |
| 333 | |
| 334 | // Create a temporary directory and file for testing |
| 335 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 336 | testFile := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmpDir, "testuser") |
| 337 | |
| 338 | // Write valid XML content |
| 339 | validContent := `<?xml version="1.0" encoding="UTF-8"?> |
| 340 | <user name="Test User" email="[email protected]"> |
| 341 | <birthday name="Alice" month="3" day="10"> |
| 342 | <reminder type="sameday"/> |
| 343 | </birthday> |
| 344 | </user>` |
| 345 | |
| 346 | if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.25.0 os/WriteFile().(testFile, []byte(validContent), 0644); err != nil { |
| 347 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to create test file: %v", err) |
| 348 | } |
| 349 | |
| 350 | now := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Datescip-go gomod github.com/golang/go/src go1.25.0 time/Date().(2024, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., 5, 9, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.25.0 time/.UTCscip-go gomod github.com/golang/go/src go1.25.0 time/UTC.) |
| 351 | conf := configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.Configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#{} |
| 352 | |
| 353 | // Process the file (which should delete it) |
| 354 | err := processSpooledFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/processSpooledFile().(testFile, tmpDir, now, conf) |
| 355 | if err != nil { |
| 356 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("processSpoolFile failed: %v", err) |
| 357 | } |
| 358 | |
| 359 | // Verify file was deleted |
| 360 | if _, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(testFile); !osscip-go gomod github.com/golang/go/src go1.25.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/IsNotExist().(err) { |
| 361 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected file to be deleted, but it still exists") |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | func TestProcessSpooledFileUnreadablescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/TestProcessSpooledFileUnreadable().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 366 | discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t) |
| 367 | |
| 368 | // Use a non-existent file path |
| 369 | nonExistentFile := "/tmp/this-file-should-not-exist-" + t.Namescip-go gomod github.com/golang/go/src go1.25.0 testing/common#Name().() |
| 370 | |
| 371 | now := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Datescip-go gomod github.com/golang/go/src go1.25.0 time/Date().(2024, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., 5, 9, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.25.0 time/.UTCscip-go gomod github.com/golang/go/src go1.25.0 time/UTC.) |
| 372 | conf := configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.Configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#{} |
| 373 | |
| 374 | // Should not return an error for unreadable files (logs and skips instead) |
| 375 | err := processSpooledFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/processSpooledFile().(nonExistentFile, "/tmp", now, conf) |
| 376 | if err != nil { |
| 377 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected no error for unreadable file, got: %v", err) |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | func TestProcessSpooledFileSimulatescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/TestProcessSpooledFileSimulate().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 382 | discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t) |
| 383 | |
| 384 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 385 | testFile := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmpDir, "testuser") |
| 386 | |
| 387 | validContent := `<?xml version="1.0" encoding="UTF-8"?> |
| 388 | <user name="Test User" email="[email protected]"> |
| 389 | <birthday name="Alice" month="3" day="10"> |
| 390 | <reminder type="sameday"/> |
| 391 | </birthday> |
| 392 | </user>` |
| 393 | |
| 394 | if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.25.0 os/WriteFile().(testFile, []byte(validContent), 0644); err != nil { |
| 395 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to create test file: %v", err) |
| 396 | } |
| 397 | |
| 398 | now := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Datescip-go gomod github.com/golang/go/src go1.25.0 time/Date().(2024, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., 5, 9, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.25.0 time/.UTCscip-go gomod github.com/golang/go/src go1.25.0 time/UTC.) |
| 399 | conf := configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.Configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#{Simulatescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#Simulate.: true} |
| 400 | |
| 401 | err := processSpooledFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/processSpooledFile().(testFile, tmpDir, now, conf) |
| 402 | if err != nil { |
| 403 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("processSpoolFile failed: %v", err) |
| 404 | } |
| 405 | |
| 406 | // In simulate mode, file should NOT be deleted |
| 407 | if _, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(testFile); osscip-go gomod github.com/golang/go/src go1.25.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/IsNotExist().(err) { |
| 408 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected file to NOT be deleted in simulate mode") |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | func TestProcessSpooledFilePermissionErrorscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/TestProcessSpooledFilePermissionError().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 413 | if osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getuidscip-go gomod github.com/golang/go/src go1.25.0 os/Getuid().() == 0 { |
| 414 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("test requires non-root user") |
| 415 | } |
| 416 | |
| 417 | discardLogsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/discardLogs().(t) |
| 418 | |
| 419 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 420 | testFile := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmpDir, "testuser") |
| 421 | |
| 422 | validContent := `<?xml version="1.0" encoding="UTF-8"?> |
| 423 | <user name="Test User" email="[email protected]"> |
| 424 | <birthday name="Alice" month="3" day="10"> |
| 425 | <reminder type="sameday"/> |
| 426 | </birthday> |
| 427 | </user>` |
| 428 | |
| 429 | if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.25.0 os/WriteFile().(testFile, []byte(validContent), 0644); err != nil { |
| 430 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to create test file: %v", err) |
| 431 | } |
| 432 | |
| 433 | // Make directory read-only to prevent deletion |
| 434 | if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Chmodscip-go gomod github.com/golang/go/src go1.25.0 os/Chmod().(tmpDir, 0555); err != nil { |
| 435 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to change directory permissions: %v", err) |
| 436 | } |
| 437 | t.Cleanupscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Cleanup().(func() { osscip-go gomod github.com/golang/go/src go1.25.0 os/.Chmodscip-go gomod github.com/golang/go/src go1.25.0 os/Chmod().(tmpDir, 0755) }) |
| 438 | |
| 439 | now := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Datescip-go gomod github.com/golang/go/src go1.25.0 time/Date().(2024, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Marchscip-go gomod github.com/golang/go/src go1.25.0 time/March., 5, 9, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.25.0 time/.UTCscip-go gomod github.com/golang/go/src go1.25.0 time/UTC.) |
| 440 | conf := configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.Configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#{} |
| 441 | |
| 442 | // Should return error when unable to delete |
| 443 | err := processSpooledFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/processSpooledFile().(testFile, tmpDir, now, conf) |
| 444 | if err == nil { |
| 445 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected error when unable to delete file") |
| 446 | } |
| 447 | } |