From 849a59a63beae7807a14854fd86693fa9e505223 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Wed, 20 May 2026 17:26:21 -0500 Subject: [PATCH] add ability to set test kv properties --- internal/processor/test/db-query_test.go | 2 +- internal/processor/test/kv-get_test.go | 32 ++++++++++++------- internal/processor/test/kv-set_test.go | 2 +- .../processor/test/pubsub-publish_test.go | 2 +- internal/test/module.go | 14 ++++++-- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/internal/processor/test/db-query_test.go b/internal/processor/test/db-query_test.go index 3341c87..9aa2fc4 100644 --- a/internal/processor/test/db-query_test.go +++ b/internal/processor/test/db-query_test.go @@ -250,7 +250,7 @@ func TestBadDbQuery(t *testing.T) { "query": "select * from test;", }, wrappedPayloadModules: map[string]common.Module{ - "test": test.NewTestKVModule("test"), + "test": test.NewTestKVModule("test", nil), }, errorString: "db.query module with id test is not a DatabaseModule", }, diff --git a/internal/processor/test/kv-get_test.go b/internal/processor/test/kv-get_test.go index 705c788..314f871 100644 --- a/internal/processor/test/kv-get_test.go +++ b/internal/processor/test/kv-get_test.go @@ -36,7 +36,9 @@ func TestKvGetFromRegistry(t *testing.T) { got, err := processorInstance.Process(t.Context(), common.WrappedPayload{ Modules: map[string]common.Module{ - "test": test.NewTestKVModule("test"), + "test": test.NewTestKVModule("test", map[string]any{ + "test": "test", + }), }, Payload: payload, }) @@ -52,19 +54,23 @@ func TestKvGetFromRegistry(t *testing.T) { func TestGoodKvGet(t *testing.T) { testCases := []struct { - name string - params map[string]any - payload any - expected any + name string + presetValues map[string]any + params map[string]any + payload any + expected any }{ { name: "basic key", + presetValues: map[string]any{ + "test": "hello", + }, params: map[string]any{ "module": "test", "key": "test", }, payload: "hello", - expected: "test", + expected: "hello", }, } for _, testCase := range testCases { @@ -85,7 +91,7 @@ func TestGoodKvGet(t *testing.T) { got, err := processorInstance.Process(t.Context(), common.WrappedPayload{ Modules: map[string]common.Module{ - "test": test.NewTestKVModule("test"), + "test": test.NewTestKVModule("test", testCase.presetValues), }, Payload: testCase.payload, }) @@ -116,7 +122,7 @@ func TestBadKvGet(t *testing.T) { "key": "test", }, wrappedPayloadModules: map[string]common.Module{ - "test": test.NewTestKVModule("test"), + "test": test.NewTestKVModule("test", nil), }, errorString: "kv.get module error: not found", }, @@ -128,7 +134,7 @@ func TestBadKvGet(t *testing.T) { "key": "test", }, wrappedPayloadModules: map[string]common.Module{ - "test": test.NewTestKVModule("test"), + "test": test.NewTestKVModule("test", nil), }, errorString: "kv.get module error: not a string", }, @@ -139,7 +145,7 @@ func TestBadKvGet(t *testing.T) { "module": "test", }, wrappedPayloadModules: map[string]common.Module{ - "test": test.NewTestKVModule("test"), + "test": test.NewTestKVModule("test", nil), }, errorString: "kv.get key error: not found", }, @@ -151,7 +157,7 @@ func TestBadKvGet(t *testing.T) { "key": 1, }, wrappedPayloadModules: map[string]common.Module{ - "test": test.NewTestKVModule("test"), + "test": test.NewTestKVModule("test", nil), }, errorString: "kv.get key error: not a string", }, @@ -240,7 +246,9 @@ func BenchmarkKvGet(b *testing.B) { b.Fatalf("kv.get failed to create processor: %s", err) } modules := map[string]common.Module{ - "test": test.NewTestKVModule("test"), + "test": test.NewTestKVModule("test", map[string]any{ + "test": "test", + }), } for b.Loop() { diff --git a/internal/processor/test/kv-set_test.go b/internal/processor/test/kv-set_test.go index d85397e..69e17ba 100644 --- a/internal/processor/test/kv-set_test.go +++ b/internal/processor/test/kv-set_test.go @@ -301,7 +301,7 @@ func BenchmarkKvSet(b *testing.B) { b.Fatalf("kv.set failed to create processor: %s", err) } modules := map[string]common.Module{ - "test": test.NewTestKVModule("test"), + "test": test.NewTestKVModule("test", nil), } count := 0 diff --git a/internal/processor/test/pubsub-publish_test.go b/internal/processor/test/pubsub-publish_test.go index c2a67cb..124a94c 100644 --- a/internal/processor/test/pubsub-publish_test.go +++ b/internal/processor/test/pubsub-publish_test.go @@ -208,7 +208,7 @@ func TestBadPubSubPublish(t *testing.T) { "topic": "test", }, wrappedPayloadModules: map[string]common.Module{ - "test": test.NewTestKVModule("test"), + "test": test.NewTestKVModule("test", nil), }, errorString: "pubsub.publish module with id test is not an OutputModule", }, diff --git a/internal/test/module.go b/internal/test/module.go index 74a0950..52c4646 100644 --- a/internal/test/module.go +++ b/internal/test/module.go @@ -62,9 +62,10 @@ func (m *TestOutputModule) Id() string { return m.id } -func NewTestKVModule(id string) *TestKVModule { +func NewTestKVModule(id string, presetValues map[string]any) *TestKVModule { return &TestKVModule{ - id: id, + id: id, + kvData: presetValues, } } @@ -89,7 +90,14 @@ func (m *TestKVModule) Id() string { } func (m *TestKVModule) Get(key string) (any, error) { - return key, nil + if m.kvData == nil { + return nil, nil + } + value, ok := m.kvData[key] + if !ok { + return nil, nil + } + return value, nil } func (m *TestKVModule) Set(key string, value any) error {