watchdog: migrate to Cobra and Viper for config management; search /etc for configs
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I65dbf466cb030dccc7025585d6282bd26a6a6964
This commit is contained in:
parent
951ed9c36f
commit
f988174145
9 changed files with 187 additions and 61 deletions
|
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
// Handles incoming analytics events
|
||||
type IngestionHandler struct {
|
||||
cfg config.Config
|
||||
cfg *config.Config
|
||||
pathNorm *normalize.PathNormalizer
|
||||
pathRegistry *aggregate.PathRegistry
|
||||
refRegistry *normalize.ReferrerRegistry
|
||||
|
|
@ -25,7 +25,7 @@ type IngestionHandler struct {
|
|||
|
||||
// Creates a new ingestion handler
|
||||
func NewIngestionHandler(
|
||||
cfg config.Config,
|
||||
cfg *config.Config,
|
||||
pathNorm *normalize.PathNormalizer,
|
||||
pathRegistry *aggregate.PathRegistry,
|
||||
refRegistry *normalize.ReferrerRegistry,
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@ func TestIngestionHandler_Pageview(t *testing.T) {
|
|||
metricsAgg := aggregate.NewMetricsAggregator(
|
||||
pathRegistry,
|
||||
aggregate.NewCustomEventRegistry(100),
|
||||
cfg,
|
||||
&cfg,
|
||||
)
|
||||
|
||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
handler := NewIngestionHandler(&cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
|
||||
body := `{"d":"example.com","p":"/home?query=1","r":"https://google.com","w":1920}`
|
||||
req := httptest.NewRequest("POST", "/api/event", bytes.NewBufferString(body))
|
||||
|
|
@ -87,10 +87,10 @@ func TestIngestionHandler_CustomEvent(t *testing.T) {
|
|||
metricsAgg := aggregate.NewMetricsAggregator(
|
||||
pathRegistry,
|
||||
aggregate.NewCustomEventRegistry(100),
|
||||
cfg,
|
||||
&cfg,
|
||||
)
|
||||
|
||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
handler := NewIngestionHandler(&cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
|
||||
body := `{"d":"example.com","p":"/signup","e":"signup"}`
|
||||
req := httptest.NewRequest("POST", "/api/event", bytes.NewBufferString(body))
|
||||
|
|
@ -125,10 +125,10 @@ func TestIngestionHandler_WrongDomain(t *testing.T) {
|
|||
metricsAgg := aggregate.NewMetricsAggregator(
|
||||
pathRegistry,
|
||||
aggregate.NewCustomEventRegistry(100),
|
||||
cfg,
|
||||
&cfg,
|
||||
)
|
||||
|
||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
handler := NewIngestionHandler(&cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
|
||||
body := `{"d":"wrong.com","p":"/home"}`
|
||||
req := httptest.NewRequest("POST", "/api/event", bytes.NewBufferString(body))
|
||||
|
|
@ -159,10 +159,10 @@ func TestIngestionHandler_MethodNotAllowed(t *testing.T) {
|
|||
metricsAgg := aggregate.NewMetricsAggregator(
|
||||
pathRegistry,
|
||||
aggregate.NewCustomEventRegistry(100),
|
||||
cfg,
|
||||
&cfg,
|
||||
)
|
||||
|
||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
handler := NewIngestionHandler(&cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
|
||||
req := httptest.NewRequest("GET", "/api/event", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
|
@ -190,10 +190,10 @@ func TestIngestionHandler_InvalidJSON(t *testing.T) {
|
|||
metricsAgg := aggregate.NewMetricsAggregator(
|
||||
pathRegistry,
|
||||
aggregate.NewCustomEventRegistry(100),
|
||||
cfg,
|
||||
&cfg,
|
||||
)
|
||||
|
||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
handler := NewIngestionHandler(&cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
|
||||
body := `{invalid json}`
|
||||
req := httptest.NewRequest("POST", "/api/event", bytes.NewBufferString(body))
|
||||
|
|
@ -229,10 +229,10 @@ func TestIngestionHandler_DeviceClassification(t *testing.T) {
|
|||
metricsAgg := aggregate.NewMetricsAggregator(
|
||||
pathRegistry,
|
||||
aggregate.NewCustomEventRegistry(100),
|
||||
cfg,
|
||||
&cfg,
|
||||
)
|
||||
|
||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
handler := NewIngestionHandler(&cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue