6f846a0a3c
Consume configurable queues, format signals (including period), share NotifyService with HTTP, and drop duplicate bodies within 1h.
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeSubscriptionDefaults(t *testing.T) {
|
|
cfg := &Config{Subscriptions: []SubscriptionConfig{{
|
|
URL: "amqps://example.invalid/vhost",
|
|
Queue: "trade.signal.notify.queue",
|
|
Source: "trade-signal",
|
|
}}}
|
|
if err := cfg.NormalizeSubscriptions(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := cfg.Subscriptions[0]
|
|
if s.Name != "trade.signal.notify.queue" {
|
|
t.Fatalf("name=%q", s.Name)
|
|
}
|
|
if s.MaxRetry != 3 {
|
|
t.Fatalf("max_retry=%d", s.MaxRetry)
|
|
}
|
|
if s.ExchangeType != "fanout" {
|
|
t.Fatalf("exchange_type=%q", s.ExchangeType)
|
|
}
|
|
if s.Formatter != "trade_signal" {
|
|
t.Fatalf("formatter=%q", s.Formatter)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeSkipsEmptyURL(t *testing.T) {
|
|
cfg := &Config{Subscriptions: []SubscriptionConfig{{
|
|
Queue: "q", Source: "s",
|
|
}}}
|
|
if err := cfg.NormalizeSubscriptions(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n := len(cfg.ActiveSubscriptions()); n != 0 {
|
|
t.Fatalf("active=%d", n)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeUnknownFormatter(t *testing.T) {
|
|
cfg := &Config{Subscriptions: []SubscriptionConfig{{
|
|
URL: "amqps://example.invalid/vhost", Queue: "q", Source: "s", Formatter: "other",
|
|
}}}
|
|
if err := cfg.NormalizeSubscriptions(); err == nil {
|
|
t.Fatal("expected error")
|
|
}
|
|
}
|
|
|
|
func TestQuantityMultiplierFor(t *testing.T) {
|
|
o := StrategyOverride{QuantityMultipliers: QuantityMultipliers{Open: 100, Add: 0}}
|
|
if o.QuantityMultiplierFor("OPEN") != 100 {
|
|
t.Fatalf("open=%v", o.QuantityMultiplierFor("OPEN"))
|
|
}
|
|
if o.QuantityMultiplierFor("ADD") != 1 {
|
|
t.Fatalf("add<=0 should be 1, got %v", o.QuantityMultiplierFor("ADD"))
|
|
}
|
|
if o.QuantityMultiplierFor("UNKNOWN") != 1 {
|
|
t.Fatalf("unknown=%v", o.QuantityMultiplierFor("UNKNOWN"))
|
|
}
|
|
}
|