| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9fa5b76 commit 8a03f4f
87 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,12 @@ jobs: | |||
| 74 | 74 | docker compose wait seed || true | |
| 75 | 75 | sleep 2 | |
| 76 | 76 | ||
| 77 | + - name: Run Handler Integration Tests | ||
| 78 | + working-directory: ./api | ||
| 79 | + env: | ||
| 80 | + USER_API_KEY: test-user-api-key | ||
| 81 | + run: go test -tags integration -v -timeout 60s ./pkg/handlers | ||
| 82 | + | ||
| 77 | 83 | - name: Run Integration Tests | |
| 78 | 84 | working-directory: ./tests | |
| 79 | 85 | run: go test -v -timeout 300s ./... | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,6 @@ package cache | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "context" | |
| 5 | - "fmt" | ||
| 6 | 5 | "time" | |
| 7 | 6 | ||
| 8 | 7 | "github.com/NdoleStudio/httpsms/pkg/telemetry" | |
@@ -31,7 +30,7 @@ func (cache *memoryCache) Get(ctx context.Context, key string) (value string, er | |||
| 31 | 30 | ||
| 32 | 31 | response, ok := cache.store.Get(key) | |
| 33 | 32 | if !ok { | |
| 34 | - return "", stacktrace.NewError(fmt.Sprintf("no item found in cache with key [%s]", key)) | ||
| 33 | + return "", stacktrace.NewError("no item found in cache with key [%s]", key) | ||
| 35 | 34 | } | |
| 36 | 35 | ||
| 37 | 36 | return response.(string), nil | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,6 @@ package cache | |||
| 3 | 3 | import ( | |
| 4 | 4 | "context" | |
| 5 | 5 | "errors" | |
| 6 | - "fmt" | ||
| 7 | 6 | "time" | |
| 8 | 7 | ||
| 9 | 8 | "github.com/NdoleStudio/httpsms/pkg/telemetry" | |
@@ -32,10 +31,10 @@ func (cache *redisCache) Get(ctx context.Context, key string) (value string, err | |||
| 32 | 31 | ||
| 33 | 32 | response, err := cache.client.Get(ctx, key).Result() | |
| 34 | 33 | if errors.Is(err, redis.Nil) { | |
| 35 | - return "", stacktrace.Propagate(err, fmt.Sprintf("no item found in redis with key [%s]", key)) | ||
| 34 | + return "", stacktrace.Propagate(err, "no item found in redis with key [%s]", key) | ||
| 36 | 35 | } | |
| 37 | 36 | if err != nil { | |
| 38 | - return "", stacktrace.Propagate(err, fmt.Sprintf("cannot get item in redis with key [%s]", key)) | ||
| 37 | + return "", stacktrace.Propagate(err, "cannot get item in redis with key [%s]", key) | ||
| 39 | 38 | } | |
| 40 | 39 | return response, nil | |
| 41 | 40 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -279,11 +279,11 @@ func (container *Container) DedicatedDB() (db *gorm.DB) { | |||
| 279 | 279 | ||
| 280 | 280 | container.logger.Debug(fmt.Sprintf("Running migrations for dedicated [%T]", db)) | |
| 281 | 281 | if err = db.AutoMigrate(&entities.Heartbeat{}); err != nil { | |
| 282 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Heartbeat{}))) | ||
| 282 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.Heartbeat{})) | ||
| 283 | 283 | } | |
| 284 | 284 | ||
| 285 | 285 | if err = db.AutoMigrate(&entities.HeartbeatMonitor{}); err != nil { | |
| 286 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.HeartbeatMonitor{}))) | ||
| 286 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.HeartbeatMonitor{})) | ||
| 287 | 287 | } | |
| 288 | 288 | ||
| 289 | 289 | return container.dedicatedDB | |
@@ -371,47 +371,47 @@ ALTER TABLE discords ADD CONSTRAINT IF NOT EXISTS uni_discords_server_id CHECK ( | |||
| 371 | 371 | } | |
| 372 | 372 | ||
| 373 | 373 | if err = db.AutoMigrate(&entities.Message{}); err != nil { | |
| 374 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Message{}))) | ||
| 374 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.Message{})) | ||
| 375 | 375 | } | |
| 376 | 376 | ||
| 377 | 377 | if err = db.AutoMigrate(&entities.MessageThread{}); err != nil { | |
| 378 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.MessageThread{}))) | ||
| 378 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.MessageThread{})) | ||
| 379 | 379 | } | |
| 380 | 380 | ||
| 381 | 381 | if err = db.AutoMigrate(&entities.User{}); err != nil { | |
| 382 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.User{}))) | ||
| 382 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.User{})) | ||
| 383 | 383 | } | |
| 384 | 384 | ||
| 385 | 385 | if err = db.AutoMigrate(&entities.MessageSendSchedule{}); err != nil { | |
| 386 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.MessageSendSchedule{}))) | ||
| 386 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.MessageSendSchedule{})) | ||
| 387 | 387 | } | |
| 388 | 388 | ||
| 389 | 389 | if err = db.AutoMigrate(&entities.Phone{}); err != nil { | |
| 390 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Phone{}))) | ||
| 390 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.Phone{})) | ||
| 391 | 391 | } | |
| 392 | 392 | ||
| 393 | 393 | if err = db.AutoMigrate(&entities.PhoneNotification{}); err != nil { | |
| 394 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.PhoneNotification{}))) | ||
| 394 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.PhoneNotification{})) | ||
| 395 | 395 | } | |
| 396 | 396 | ||
| 397 | 397 | if err = db.AutoMigrate(&entities.BillingUsage{}); err != nil { | |
| 398 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.BillingUsage{}))) | ||
| 398 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.BillingUsage{})) | ||
| 399 | 399 | } | |
| 400 | 400 | ||
| 401 | 401 | if err = db.AutoMigrate(&entities.Webhook{}); err != nil { | |
| 402 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Webhook{}))) | ||
| 402 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.Webhook{})) | ||
| 403 | 403 | } | |
| 404 | 404 | ||
| 405 | 405 | if err = db.AutoMigrate(&entities.Discord{}); err != nil { | |
| 406 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Discord{}))) | ||
| 406 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.Discord{})) | ||
| 407 | 407 | } | |
| 408 | 408 | ||
| 409 | 409 | if err = db.AutoMigrate(&entities.Integration3CX{}); err != nil { | |
| 410 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Integration3CX{}))) | ||
| 410 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.Integration3CX{})) | ||
| 411 | 411 | } | |
| 412 | 412 | ||
| 413 | 413 | if err = db.AutoMigrate(&entities.PhoneAPIKey{}); err != nil { | |
| 414 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.PhoneAPIKey{}))) | ||
| 414 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot migrate %T", &entities.PhoneAPIKey{})) | ||
| 415 | 415 | } | |
| 416 | 416 | ||
| 417 | 417 | return container.db | |
@@ -423,8 +423,7 @@ func (container *Container) FirebaseApp() (app *firebase.App) { | |||
| 423 | 423 | ||
| 424 | 424 | app, err := firebase.NewApp(context.Background(), nil, option.WithCredentialsJSON(container.FirebaseCredentials())) | |
| 425 | 425 | if err != nil { | |
| 426 | - msg := "cannot initialize firebase application" | ||
| 427 | - container.logger.Fatal(stacktrace.Propagate(err, msg)) | ||
| 426 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot initialize firebase application")) | ||
| 428 | 427 | } | |
| 429 | 428 | return app | |
| 430 | 429 | } | |
@@ -445,7 +444,7 @@ func (container *Container) Cache() cache.Cache { | |||
| 445 | 444 | container.logger.Debug("creating cache.Cache") | |
| 446 | 445 | opt, err := redis.ParseURL(os.Getenv("REDIS_URL")) | |
| 447 | 446 | if err != nil { | |
| 448 | - container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot parse redis url [%s]", os.Getenv("REDIS_URL")))) | ||
| 447 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot parse redis url [%s]", os.Getenv("REDIS_URL"))) | ||
| 449 | 448 | } | |
| 450 | 449 | if strings.HasPrefix(os.Getenv("REDIS_URL"), "rediss://") { | |
| 451 | 450 | opt.TLSConfig = &tls.Config{ | |
@@ -473,8 +472,7 @@ func (container *Container) FirebaseAuthClient() (client *auth.Client) { | |||
| 473 | 472 | container.logger.Debug(fmt.Sprintf("creating %T", client)) | |
| 474 | 473 | authClient, err := container.FirebaseApp().Auth(context.Background()) | |
| 475 | 474 | if err != nil { | |
| 476 | - msg := "cannot initialize firebase auth client" | ||
| 477 | - container.logger.Fatal(stacktrace.Propagate(err, msg)) | ||
| 475 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot initialize firebase auth client")) | ||
| 478 | 476 | } | |
| 479 | 477 | return authClient | |
| 480 | 478 | } | |
@@ -553,8 +551,7 @@ func (container *Container) FCMClient() services.FCMClient { | |||
| 553 | 551 | container.logger.Debug("creating FirebaseFCMClient") | |
| 554 | 552 | messagingClient, err := container.FirebaseApp().Messaging(context.Background()) | |
| 555 | 553 | if err != nil { | |
| 556 | - msg := "cannot initialize firebase messaging client" | ||
| 557 | - container.logger.Fatal(stacktrace.Propagate(err, msg)) | ||
| 554 | + container.logger.Fatal(stacktrace.Propagate(err, "cannot initialize firebase messaging client")) | ||
| 558 | 555 | } | |
| 559 | 556 | return services.NewFirebaseFCMClient(messagingClient) | |
| 560 | 557 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,8 +66,7 @@ func (h *AttachmentHandler) GetAttachment(c fiber.Ctx) error { | |||
| 66 | 66 | ||
| 67 | 67 | data, err := h.storage.Download(ctx, path) | |
| 68 | 68 | if err != nil { | |
| 69 | - msg := fmt.Sprintf("cannot download attachment from path [%s]", path) | ||
| 70 | - ctxLogger.Warn(stacktrace.Propagate(err, msg)) | ||
| 69 | + ctxLogger.Warn(stacktrace.Propagate(err, "cannot download attachment from path [%s]", path)) | ||
| 71 | 70 | if stacktrace.GetCode(err) == repositories.ErrCodeNotFound { | |
| 72 | 71 | return h.responseNotFound(c, "attachment not found") | |
| 73 | 72 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,21 +65,18 @@ func (h *BillingHandler) UsageHistory(c fiber.Ctx) error { | |||
| 65 | 65 | ||
| 66 | 66 | var request requests.BillingUsageHistory | |
| 67 | 67 | if err := c.Bind().Query(&request); err != nil { | |
| 68 | - msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.Body(), request) | ||
| 69 | - ctxLogger.Warn(stacktrace.Propagate(err, msg)) | ||
| 68 | + ctxLogger.Warn(stacktrace.Propagate(err, "cannot marshall params [%s] into %T", c.Body(), request)) | ||
| 70 | 69 | return h.responseBadRequest(c, err) | |
| 71 | 70 | } | |
| 72 | 71 | ||
| 73 | 72 | if errors := h.validator.ValidateHistory(ctx, request.Sanitize()); len(errors) != 0 { | |
| 74 | - msg := fmt.Sprintf("validation errors [%s], while fetching heartbeats [%+#v]", spew.Sdump(errors), request) | ||
| 75 | - ctxLogger.Warn(stacktrace.NewError(msg)) | ||
| 73 | + ctxLogger.Warn(stacktrace.NewError("validation errors [%s], while fetching heartbeats [%+#v]", spew.Sdump(errors), request)) | ||
| 76 | 74 | return h.responseUnprocessableEntity(c, errors, "validation errors while fetching usage history") | |
| 77 | 75 | } | |
| 78 | 76 | ||
| 79 | 77 | heartbeats, err := h.service.GetUsageHistory(ctx, h.userIDFomContext(c), request.ToIndexParams()) | |
| 80 | 78 | if err != nil { | |
| 81 | - msg := fmt.Sprintf("cannot get billing usage history with params [%+#v]", request) | ||
| 82 | - ctxLogger.Error(stacktrace.Propagate(err, msg)) | ||
| 79 | + ctxLogger.Error(stacktrace.Propagate(err, "cannot get billing usage history with params [%+#v]", request)) | ||
| 83 | 80 | return h.responseInternalServerError(c) | |
| 84 | 81 | } | |
| 85 | 82 | ||
@@ -107,8 +104,7 @@ func (h *BillingHandler) Usage(c fiber.Ctx) error { | |||
| 107 | 104 | ||
| 108 | 105 | billingUsage, err := h.service.GetCurrentUsage(ctx, h.userIDFomContext(c)) | |
| 109 | 106 | if err != nil { | |
| 110 | - msg := fmt.Sprintf("cannot get current usage record for user [%s]", h.userFromContext(c)) | ||
| 111 | - ctxLogger.Error(stacktrace.Propagate(err, msg)) | ||
| 107 | + ctxLogger.Error(stacktrace.Propagate(err, "cannot get current usage record for user [%s]", h.userFromContext(c))) | ||
| 112 | 108 | return h.responseInternalServerError(c) | |
| 113 | 109 | } | |
| 114 | 110 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,8 +67,7 @@ func (h *BulkMessageHandler) Index(c fiber.Ctx) error { | |||
| 67 | 67 | ||
| 68 | 68 | orders, err := h.messageService.GetBulkMessages(ctx, h.userIDFomContext(c)) | |
| 69 | 69 | if err != nil { | |
| 70 | - msg := fmt.Sprintf("cannot fetch bulk messages for user [%s]", h.userIDFomContext(c)) | ||
| 71 | - ctxLogger.Error(stacktrace.Propagate(err, msg)) | ||
| 70 | + ctxLogger.Error(stacktrace.Propagate(err, "cannot fetch bulk messages for user [%s]", h.userIDFomContext(c))) | ||
| 72 | 71 | return h.responseInternalServerError(c) | |
| 73 | 72 | } | |
| 74 | 73 | ||
@@ -95,20 +94,18 @@ func (h *BulkMessageHandler) Store(c fiber.Ctx) error { | |||
| 95 | 94 | ||
| 96 | 95 | file, err := c.FormFile("document") | |
| 97 | 96 | if err != nil { | |
| 98 | - msg := fmt.Sprintf("cannot fetch file with name [%s] from request", "document") | ||
| 99 | - ctxLogger.Warn(stacktrace.Propagate(err, msg)) | ||
| 97 | + ctxLogger.Warn(stacktrace.Propagate(err, "cannot fetch file with name [%s] from request", "document")) | ||
| 100 | 98 | return h.responseBadRequest(c, err) | |
| 101 | 99 | } | |
| 102 | 100 | ||
| 103 | 101 | messages, userLocation, validationErrors := h.validator.ValidateStore(ctx, h.userIDFomContext(c), file) | |
| 104 | 102 | if len(validationErrors) != 0 { | |
| 105 | - msg := fmt.Sprintf("validation errors [%s], while sending bulk sms from CSV file [%s] for [%s]", spew.Sdump(validationErrors), file.Filename, h.userIDFomContext(c)) | ||
| 106 | - ctxLogger.Warn(stacktrace.NewError(msg)) | ||
| 103 | + ctxLogger.Warn(stacktrace.NewError("validation errors [%s], while sending bulk sms from CSV file [%s] for [%s]", spew.Sdump(validationErrors), file.Filename, h.userIDFomContext(c))) | ||
| 107 | 104 | return h.responseUnprocessableEntity(c, validationErrors, "validation errors while sending bulk SMS") | |
| 108 | 105 | } | |
| 109 | 106 | ||
| 110 | 107 | if msg := h.billingService.IsEntitledWithCount(ctx, h.userIDFomContext(c), uint(len(messages))); msg != nil { | |
| 111 | - ctxLogger.Warn(stacktrace.NewError(fmt.Sprintf("user with ID [%s] is not entitled to send [%d] messages", h.userIDFomContext(c), len(messages)))) | ||
| 108 | + ctxLogger.Warn(stacktrace.NewError("user with ID [%s] is not entitled to send [%d] messages", h.userIDFomContext(c), len(messages))) | ||
| 112 | 109 | return h.responsePaymentRequired(c, *msg) | |
| 113 | 110 | } | |
| 114 | 111 | ||
@@ -135,8 +132,8 @@ func (h *BulkMessageHandler) Store(c fiber.Ctx) error { | |||
| 135 | 132 | ) | |
| 136 | 133 | if err != nil { | |
| 137 | 134 | count.Add(-1) | |
| 138 | - msg := fmt.Sprintf("cannot send message with payload [%s] at index [%d]", spew.Sdump(message), index) | ||
| 139 | - ctxLogger.Error(stacktrace.Propagate(err, msg)) | ||
| 135 | + | ||
| 136 | + ctxLogger.Error(stacktrace.Propagate(err, "cannot send message with payload [%s] at index [%d]", spew.Sdump(message), index)) | ||
| 140 | 137 | } | |
| 141 | 138 | wg.Done() | |
| 142 | 139 | }(message, perPhoneIndex) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments