| 1 | package configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/ |
| 2 | |
| 3 | import ( |
| 4 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 5 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 6 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 7 | ) |
| 8 | |
| 9 | func TestReadConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/TestReadConfig().(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#) { |
| 10 | const defaultMailFrom = "root@localhost" |
| 11 | const defaultMaxEvents = 10000 |
| 12 | const defaultMaxRecipients = 200 |
| 13 | |
| 14 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("NonExistentConfigFile", 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#) { |
| 15 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().("/nonexistent", "file.conf") |
| 16 | if config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom. != defaultMailFrom { |
| 17 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected default MailFrom value to be '%s', got '%s'", defaultMailFrom, config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom.) |
| 18 | } |
| 19 | }) |
| 20 | |
| 21 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("ValidConfigFile", 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#) { |
| 22 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 23 | configFile := 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, "test.conf") |
| 24 | |
| 25 | configContent := `# Test configuration file |
| 26 | send_reminders=false |
| 27 | smtp_server=mail.example.com # default |
| 28 | smtp_ssl=true |
| 29 | smtp_username=testuser # change? |
| 30 | smtp_password=testpass |
| 31 | [email protected] |
| 32 | max_events_per_user=5000 |
| 33 | max_recipients_per_event=150 |
| 34 | ` |
| 35 | 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().(configFile, []byte(configContent), 0644) |
| 36 | if err != nil { |
| 37 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 38 | } |
| 39 | |
| 40 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 41 | |
| 42 | if config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders. != false { |
| 43 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SendReminders to be false, got %v", config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders.) |
| 44 | } |
| 45 | if config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer. != "mail.example.com" { |
| 46 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpServer to be 'mail.example.com', got '%s'", config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer.) |
| 47 | } |
| 48 | if config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl. != true { |
| 49 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpSsl to be true, got %v", config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl.) |
| 50 | } |
| 51 | if config.SmtpUsernamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpUsername. != "testuser" { |
| 52 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpUsername to be 'testuser', got '%s'", config.SmtpUsernamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpUsername.) |
| 53 | } |
| 54 | if config.SmtpPasswordscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpPassword. != "testpass" { |
| 55 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpPassword to be 'testpass', got '%s'", config.SmtpPasswordscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpPassword.) |
| 56 | } |
| 57 | if config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom. != "[email protected]" { |
| 58 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MailFrom to be '[email protected]', got '%s'", config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom.) |
| 59 | } |
| 60 | if config.MaxEventsPerUserscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxEventsPerUser. != 5000 { |
| 61 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MaxEventsPerUser to be 5000, got %d", config.MaxEventsPerUserscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxEventsPerUser.) |
| 62 | } |
| 63 | if config.MaxRecipientsPerEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxRecipientsPerEvent. != 150 { |
| 64 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MaxRecipientsPerEvent to be 150, got %d", config.MaxRecipientsPerEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxRecipientsPerEvent.) |
| 65 | } |
| 66 | }) |
| 67 | |
| 68 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("ValidConfigFileBooleans", 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#) { |
| 69 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 70 | configFile := 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, "test.conf") |
| 71 | |
| 72 | configContent := `# Test configuration file |
| 73 | send_reminders=no |
| 74 | smtp_ssl=yes |
| 75 | ` |
| 76 | 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().(configFile, []byte(configContent), 0644) |
| 77 | if err != nil { |
| 78 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 79 | } |
| 80 | |
| 81 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 82 | |
| 83 | if config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders. != false { |
| 84 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SendReminders to be false, got %v", config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders.) |
| 85 | } |
| 86 | if config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl. != true { |
| 87 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpSsl to be true, got %v", config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl.) |
| 88 | } |
| 89 | }) |
| 90 | |
| 91 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("ConfigWithCommentsAndWhitespace", 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#) { |
| 92 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 93 | configFile := 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, "test.conf") |
| 94 | |
| 95 | configContent := `# This is a comment |
| 96 | # Another comment |
| 97 | send_reminders = 1 |
| 98 | smtp_server = localhost |
| 99 | # More comments with # marks in it too |
| 100 | smtp_ssl=0 |
| 101 | ` |
| 102 | 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().(configFile, []byte(configContent), 0644) |
| 103 | if err != nil { |
| 104 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 105 | } |
| 106 | |
| 107 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 108 | |
| 109 | if config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders. != true { |
| 110 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SendReminders to be true, got %v", config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders.) |
| 111 | } |
| 112 | if config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer. != "localhost" { |
| 113 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpServer to be 'localhost', got '%s'", config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer.) |
| 114 | } |
| 115 | if config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl. != false { |
| 116 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpSsl to be false, got %v", config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl.) |
| 117 | } |
| 118 | if config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom. != defaultMailFrom { |
| 119 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected default MailFrom value to be '%s', got '%s'", defaultMailFrom, config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom.) |
| 120 | } |
| 121 | }) |
| 122 | |
| 123 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("InvalidBooleanValues", 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#) { |
| 124 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 125 | configFile := 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, "test.conf") |
| 126 | |
| 127 | configContent := `send_reminders=invalid_bool |
| 128 | |
| 129 | smtp_ssl=not_a_boolean |
| 130 | |
| 131 | smtp_server=valid.server.com |
| 132 | max_xml_size_mb=1000 |
| 133 | ` |
| 134 | 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().(configFile, []byte(configContent), 0644) |
| 135 | if err != nil { |
| 136 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 137 | } |
| 138 | |
| 139 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 140 | |
| 141 | // Boolean values should remain default due to invalid input |
| 142 | if config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders. != true { |
| 143 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SendReminders to be true (default due to invalid input), got %v", config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders.) |
| 144 | } |
| 145 | if config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl. != false { |
| 146 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpSsl to be false (default due to invalid input), got %v", config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl.) |
| 147 | } |
| 148 | |
| 149 | // Valid string value should be set |
| 150 | if config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer. != "valid.server.com" { |
| 151 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpServer to be 'valid.server.com', got '%s'", config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer.) |
| 152 | } |
| 153 | |
| 154 | // Valid integer value should be set |
| 155 | const max_xml_bytes = 1_000 * 1024 * 1024 |
| 156 | if config.MaxXMLSizeBytesscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxXMLSizeBytes. != max_xml_bytes { |
| 157 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MaxXMLSizeBytes to be %d bytes, got %d bytes", max_xml_bytes, config.MaxXMLSizeBytesscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxXMLSizeBytes.) |
| 158 | } |
| 159 | |
| 160 | }) |
| 161 | |
| 162 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("InvalidLineFormat", 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#) { |
| 163 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 164 | configFile := 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, "test.conf") |
| 165 | |
| 166 | configContent := `smtp_server=valid.server.com |
| 167 | invalid_line_without_equal_sign |
| 168 | smtp_ssl==1 |
| 169 | [email protected] |
| 170 | ` |
| 171 | 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().(configFile, []byte(configContent), 0644) |
| 172 | if err != nil { |
| 173 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 174 | } |
| 175 | |
| 176 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 177 | |
| 178 | // Should process the first valid line but stop at invalid line |
| 179 | if config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer. != "valid.server.com" { |
| 180 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpServer to be 'valid.server.com', got '%s'", config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer.) |
| 181 | } |
| 182 | |
| 183 | if config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl. != false { |
| 184 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpSsl to be false (default due to invalid input), got %v", config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl.) |
| 185 | } |
| 186 | |
| 187 | // The line after the invalid one should still be processed |
| 188 | if config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom. != "[email protected]" { |
| 189 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MailFrom to be '[email protected]', got '%s'", config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom.) |
| 190 | } |
| 191 | }) |
| 192 | |
| 193 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("InvalidSmtpHostname", 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#) { |
| 194 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 195 | configFile := 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, "test.conf") |
| 196 | |
| 197 | // Get the default hostname for comparison |
| 198 | hostname, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Hostnamescip-go gomod github.com/golang/go/src go1.25.0 os/Hostname().() |
| 199 | if err != nil { |
| 200 | hostname = "localhost" |
| 201 | } |
| 202 | |
| 203 | configContent := `smtp_server=.invalid.hostname |
| 204 | smtp_ssl=true |
| 205 | mail_from=test@localhost |
| 206 | ` |
| 207 | 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().(configFile, []byte(configContent), 0644) |
| 208 | if err != nil { |
| 209 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 210 | } |
| 211 | |
| 212 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 213 | |
| 214 | // Invalid SMTP hostname should be rejected and default value kept |
| 215 | if config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer. != hostname { |
| 216 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpServer to be '%s' (default due to invalid hostname), got '%s'", hostname, config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer.) |
| 217 | } |
| 218 | |
| 219 | // Other valid values should still be set |
| 220 | if config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl. != true { |
| 221 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpSsl to be true, got %v", config.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl.) |
| 222 | } |
| 223 | if config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom. != "test@localhost" { |
| 224 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MailFrom to be 'test@localhost', got '%s'", config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom.) |
| 225 | } |
| 226 | }) |
| 227 | |
| 228 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("InvalidMailFrom", 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#) { |
| 229 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 230 | configFile := 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, "test.conf") |
| 231 | |
| 232 | configContent := `mail_from=user@@example.com |
| 233 | max_events_per_user=-10 |
| 234 | max_recipients_per_event=100000 |
| 235 | max_xml_size_mb=0 |
| 236 | smtp_server=mail.example.com |
| 237 | ` |
| 238 | 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().(configFile, []byte(configContent), 0644) |
| 239 | if err != nil { |
| 240 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 241 | } |
| 242 | |
| 243 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 244 | |
| 245 | // Invalid mail_from should be rejected, default should be used |
| 246 | if config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom. != defaultMailFrom { |
| 247 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MailFrom to be default '%s', got '%s'", defaultMailFrom, config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom.) |
| 248 | } |
| 249 | |
| 250 | // Invalid max_events_per_user should be rejected, default should be used |
| 251 | if config.MaxEventsPerUserscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxEventsPerUser. != defaultMaxEvents { |
| 252 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MaxEventsPerUser to be default %d, got '%d'", defaultMaxEvents, config.MaxEventsPerUserscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxEventsPerUser.) |
| 253 | } |
| 254 | |
| 255 | // Invalid max_recipients_per_event should be rejected, default should be used |
| 256 | if config.MaxRecipientsPerEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxRecipientsPerEvent. != defaultMaxRecipients { |
| 257 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MaxRecipientsPerEvent to be default %d, got %d", defaultMaxRecipients, config.MaxRecipientsPerEventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxRecipientsPerEvent.) |
| 258 | } |
| 259 | |
| 260 | // Invalid max_xml_size_mb should be rejected, default should be used |
| 261 | const defaultMaxXML = 50 * 1024 * 1024 |
| 262 | if config.MaxXMLSizeBytesscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxXMLSizeBytes. != defaultMaxXML { |
| 263 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MaxXMLSizeBytes to be default %d, got %d", defaultMaxXML, config.MaxXMLSizeBytesscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxXMLSizeBytes.) |
| 264 | } |
| 265 | |
| 266 | // Other valid values should still be set |
| 267 | if config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer. != "mail.example.com" { |
| 268 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpServer to be 'mail.example.com', got '%s'", config.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer.) |
| 269 | } |
| 270 | }) |
| 271 | |
| 272 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("MailFromWithDisplayName", 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#) { |
| 273 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 274 | configFile := 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, "test.conf") |
| 275 | |
| 276 | // Try to use email with display name format |
| 277 | configContent := `mail_from=John Doe <[email protected]> |
| 278 | ` |
| 279 | 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().(configFile, []byte(configContent), 0644) |
| 280 | if err != nil { |
| 281 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 282 | } |
| 283 | |
| 284 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 285 | |
| 286 | // Display name format should be rejected, default should be used |
| 287 | if config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom. != defaultMailFrom { |
| 288 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MailFrom to be default '%s' due to display name format, got '%s'", defaultMailFrom, config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom.) |
| 289 | } |
| 290 | }) |
| 291 | |
| 292 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("EmptyConfigFile", 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#) { |
| 293 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 294 | configFile := 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, "test.conf") |
| 295 | |
| 296 | 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().(configFile, []byte(""), 0644) |
| 297 | if err != nil { |
| 298 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 299 | } |
| 300 | |
| 301 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 302 | |
| 303 | // All values should be defaults |
| 304 | if config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders. != true { |
| 305 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SendReminders to be true, got %v", config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders.) |
| 306 | } |
| 307 | if config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom. != defaultMailFrom { |
| 308 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MailFrom to be '%s', got '%s'", defaultMailFrom, config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom.) |
| 309 | } |
| 310 | }) |
| 311 | |
| 312 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("OnlyCommentsConfigFile", 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 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 314 | configFile := 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, "test.conf") |
| 315 | |
| 316 | configContent := `# This is a comment |
| 317 | # Another comment |
| 318 | # Yet another comment |
| 319 | ` |
| 320 | 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().(configFile, []byte(configContent), 0644) |
| 321 | if err != nil { |
| 322 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 323 | } |
| 324 | |
| 325 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 326 | |
| 327 | // All values should be defaults |
| 328 | if config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders. != true { |
| 329 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SendReminders to be true, got %v", config.SendRemindersscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SendReminders.) |
| 330 | } |
| 331 | if config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom. != defaultMailFrom { |
| 332 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected MailFrom to be '%s', got '%s'", defaultMailFrom, config.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom.) |
| 333 | } |
| 334 | }) |
| 335 | |
| 336 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("SmtpUsernameTooLong", 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#) { |
| 337 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 338 | configFile := 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, "test.conf") |
| 339 | |
| 340 | longUsername := string(make([]byte, 129)) // 129 characters |
| 341 | for i := range longUsername { |
| 342 | longUsername = string([]byte{byte('a' + (i % 26))}) + longUsername[1:] |
| 343 | } |
| 344 | |
| 345 | configContent := `smtp_username=` + longUsername + ` |
| 346 | smtp_password=validpass |
| 347 | ` |
| 348 | 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().(configFile, []byte(configContent), 0644) |
| 349 | if err != nil { |
| 350 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 351 | } |
| 352 | |
| 353 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 354 | |
| 355 | // Username that's too long should be rejected, default (empty string) should be used |
| 356 | if config.SmtpUsernamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpUsername. != "" { |
| 357 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpUsername to be empty (default) due to excessive length, got '%s'", config.SmtpUsernamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpUsername.) |
| 358 | } |
| 359 | |
| 360 | // Other valid values should still be set |
| 361 | if config.SmtpPasswordscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpPassword. != "validpass" { |
| 362 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpPassword to be 'validpass', got '%s'", config.SmtpPasswordscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpPassword.) |
| 363 | } |
| 364 | }) |
| 365 | |
| 366 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("SmtpPasswordTooLong", 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#) { |
| 367 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 368 | configFile := 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, "test.conf") |
| 369 | |
| 370 | longPassword := string(make([]byte, 129)) // 129 characters long |
| 371 | for i := range longPassword { |
| 372 | longPassword = string([]byte{byte('A' + (i % 26))}) + longPassword[1:] |
| 373 | } |
| 374 | |
| 375 | configContent := `smtp_username=validuser |
| 376 | smtp_password=` + longPassword + ` |
| 377 | ` |
| 378 | 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().(configFile, []byte(configContent), 0644) |
| 379 | if err != nil { |
| 380 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create test config file: %v", err) |
| 381 | } |
| 382 | |
| 383 | config := readConfigscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/readConfig().(tmpDir, "test.conf") |
| 384 | |
| 385 | // Password that's too long should be rejected, default (empty string) should be used |
| 386 | if config.SmtpPasswordscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpPassword. != "" { |
| 387 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpPassword to be empty (default) due to excessive length, got '%s'", config.SmtpPasswordscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpPassword.) |
| 388 | } |
| 389 | |
| 390 | // Other valid values should still be set |
| 391 | if config.SmtpUsernamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpUsername. != "validuser" { |
| 392 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected SmtpUsername to be 'validuser', got '%s'", config.SmtpUsernamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpUsername.) |
| 393 | } |
| 394 | }) |
| 395 | } |
| 396 | |
| 397 | func TestGetUserConfigFilePathscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/TestGetUserConfigFilePath().(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#) { |
| 398 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("NoConfigFiles", 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#) { |
| 399 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 400 | path, _ := GetUserConfigFilenamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/GetUserConfigFilename().(tmpDir) |
| 401 | |
| 402 | if path != "" { |
| 403 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected path to be empty, got '%s'", path) |
| 404 | } |
| 405 | }) |
| 406 | |
| 407 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("OnlyLegacyFile", 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#) { |
| 408 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 409 | legacyPath := 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, LegacyUserConfigFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/LegacyUserConfigFile.) |
| 410 | |
| 411 | 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().(legacyPath, []byte("legacy content"), 0644); err != nil { |
| 412 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create legacy config file: %v", err) |
| 413 | } |
| 414 | |
| 415 | filename, _ := GetUserConfigFilenamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/GetUserConfigFilename().(tmpDir) |
| 416 | if filename != LegacyUserConfigFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/LegacyUserConfigFile. { |
| 417 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected path to be '%s', got '%s'", LegacyUserConfigFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/LegacyUserConfigFile., filename) |
| 418 | } |
| 419 | }) |
| 420 | |
| 421 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("OnlyPreferredFile", 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#) { |
| 422 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 423 | if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.25.0 os/MkdirAll().(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, UserConfigDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/UserConfigDir.), 0755); err != nil { |
| 424 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create preferred config directory: %v", err) |
| 425 | } |
| 426 | |
| 427 | preferredFilename := 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().(UserConfigDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/UserConfigDir., UserConfigFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/UserConfigFile.) |
| 428 | 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().(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, preferredFilename), []byte("preferred content"), 0644); err != nil { |
| 429 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create preferred config file: %v", err) |
| 430 | } |
| 431 | |
| 432 | filename, _ := GetUserConfigFilenamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/GetUserConfigFilename().(tmpDir) |
| 433 | |
| 434 | if filename != preferredFilename { |
| 435 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected path to be '%s', got '%s'", preferredFilename, filename) |
| 436 | } |
| 437 | }) |
| 438 | |
| 439 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("BothFilesExist", 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#) { |
| 440 | tmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 441 | |
| 442 | // Create legacy file |
| 443 | legacyPath := 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, LegacyUserConfigFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/LegacyUserConfigFile.) |
| 444 | 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().(legacyPath, []byte("legacy content"), 0644); err != nil { |
| 445 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create legacy config file: %v", err) |
| 446 | } |
| 447 | |
| 448 | // Create preferred file |
| 449 | if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.25.0 os/MkdirAll().(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, UserConfigDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/UserConfigDir.), 0755); err != nil { |
| 450 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create preferred config directory: %v", err) |
| 451 | } |
| 452 | |
| 453 | preferredFilename := 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().(UserConfigDirscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/UserConfigDir., UserConfigFilescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/UserConfigFile.) |
| 454 | 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().(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, preferredFilename), []byte("preferred content"), 0644); err != nil { |
| 455 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Failed to create preferred config file: %v", err) |
| 456 | } |
| 457 | |
| 458 | filename, _ := GetUserConfigFilenamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/GetUserConfigFilename().(tmpDir) |
| 459 | |
| 460 | // Should prefer the new config file over the legacy one |
| 461 | if filename != preferredFilename { |
| 462 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected path to be '%s' (preferred), got '%s'", preferredFilename, filename) |
| 463 | } |
| 464 | }) |
| 465 | } |