36 lines
1.4 KiB
Go
36 lines
1.4 KiB
Go
package gosqs
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"shared-sqs/app/models"
|
|
"shared-sqs/app/tenant"
|
|
)
|
|
|
|
// TestTenantQueueURL — проверяет формирование QueueUrl: публичный ExternalURLBase
|
|
// приоритетнее локального формата, пустое значение даёт старый формат.
|
|
func TestTenantQueueURL(t *testing.T) {
|
|
old := models.CurrentEnvironment
|
|
defer func() { models.CurrentEnvironment = old }()
|
|
|
|
tt := &tenant.Tenant{ID: "t-abc123"}
|
|
|
|
// Публичный адрес; хвостовой слеш обрезается.
|
|
models.CurrentEnvironment = models.Environment{ExternalURLBase: "https://sqs.sinefo.ru/"}
|
|
if got, want := tenantQueueURL(tt, "orders"), "https://sqs.sinefo.ru/t-abc123/orders"; got != want {
|
|
t.Fatalf("external base: got %q, want %q", got, want)
|
|
}
|
|
|
|
// Пусто → старый формат с region.
|
|
models.CurrentEnvironment = models.Environment{Host: "goaws.com", Port: "4100", Region: "us-east-1"}
|
|
if got, want := tenantQueueURL(tt, "orders"), "http://us-east-1.goaws.com:4100/t-abc123/orders"; got != want {
|
|
t.Fatalf("local format (region): got %q, want %q", got, want)
|
|
}
|
|
|
|
// Пусто, без region.
|
|
models.CurrentEnvironment = models.Environment{Host: "localhost", Port: "4100"}
|
|
if got, want := tenantQueueURL(tt, "orders"), "http://localhost:4100/t-abc123/orders"; got != want {
|
|
t.Fatalf("local format (no region): got %q, want %q", got, want)
|
|
}
|
|
}
|