(t *testing.T)
| 188 | } |
| 189 | |
| 190 | func TestSettingsValidate(t *testing.T) { |
| 191 | t.Parallel() |
| 192 | |
| 193 | app, _ := tests.NewTestApp() |
| 194 | defer app.Cleanup() |
| 195 | |
| 196 | s := app.Settings() |
| 197 | |
| 198 | // set invalid settings data |
| 199 | s.SuperuserIPs = []string{"127.0.0.1", ""} |
| 200 | s.Meta.AppName = "" |
| 201 | s.Logs.MaxDays = -10 |
| 202 | s.SMTP.Enabled = true |
| 203 | s.SMTP.Host = "" |
| 204 | s.S3.Enabled = true |
| 205 | s.S3.Endpoint = "invalid" |
| 206 | s.Backups.Cron = "invalid" |
| 207 | s.Backups.CronMaxKeep = -10 |
| 208 | s.Batch.Enabled = true |
| 209 | s.Batch.MaxRequests = -1 |
| 210 | s.Batch.Timeout = -1 |
| 211 | s.RateLimits.Enabled = true |
| 212 | s.RateLimits.Rules = nil |
| 213 | |
| 214 | // check if Validate() is triggering the members validate methods. |
| 215 | err := app.Validate(s) |
| 216 | if err == nil { |
| 217 | t.Fatalf("Expected error, got nil") |
| 218 | } |
| 219 | |
| 220 | expectations := []string{ |
| 221 | `"superuserIPs":{`, |
| 222 | `"meta":{`, |
| 223 | `"logs":{`, |
| 224 | `"smtp":{`, |
| 225 | `"s3":{`, |
| 226 | `"backups":{`, |
| 227 | `"batch":{`, |
| 228 | `"rateLimits":{`, |
| 229 | } |
| 230 | |
| 231 | errBytes, _ := json.Marshal(err) |
| 232 | jsonErr := string(errBytes) |
| 233 | for _, expected := range expectations { |
| 234 | if !strings.Contains(jsonErr, expected) { |
| 235 | t.Errorf("Expected error key %s in %v", expected, jsonErr) |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | func TestMetaConfigValidate(t *testing.T) { |
| 241 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…