add ability to set test kv properties

This commit is contained in:
Joel Wetzell
2026-05-20 17:26:21 -05:00
parent 00b03197c2
commit 849a59a63b
5 changed files with 34 additions and 18 deletions
+1 -1
View File
@@ -250,7 +250,7 @@ func TestBadDbQuery(t *testing.T) {
"query": "select * from test;", "query": "select * from test;",
}, },
wrappedPayloadModules: map[string]common.Module{ 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", errorString: "db.query module with id test is not a DatabaseModule",
}, },
+20 -12
View File
@@ -36,7 +36,9 @@ func TestKvGetFromRegistry(t *testing.T) {
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{ got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
Modules: map[string]common.Module{ Modules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test", map[string]any{
"test": "test",
}),
}, },
Payload: payload, Payload: payload,
}) })
@@ -52,19 +54,23 @@ func TestKvGetFromRegistry(t *testing.T) {
func TestGoodKvGet(t *testing.T) { func TestGoodKvGet(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
params map[string]any presetValues map[string]any
payload any params map[string]any
expected any payload any
expected any
}{ }{
{ {
name: "basic key", name: "basic key",
presetValues: map[string]any{
"test": "hello",
},
params: map[string]any{ params: map[string]any{
"module": "test", "module": "test",
"key": "test", "key": "test",
}, },
payload: "hello", payload: "hello",
expected: "test", expected: "hello",
}, },
} }
for _, testCase := range testCases { for _, testCase := range testCases {
@@ -85,7 +91,7 @@ func TestGoodKvGet(t *testing.T) {
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{ got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
Modules: map[string]common.Module{ Modules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test", testCase.presetValues),
}, },
Payload: testCase.payload, Payload: testCase.payload,
}) })
@@ -116,7 +122,7 @@ func TestBadKvGet(t *testing.T) {
"key": "test", "key": "test",
}, },
wrappedPayloadModules: map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test", nil),
}, },
errorString: "kv.get module error: not found", errorString: "kv.get module error: not found",
}, },
@@ -128,7 +134,7 @@ func TestBadKvGet(t *testing.T) {
"key": "test", "key": "test",
}, },
wrappedPayloadModules: map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test", nil),
}, },
errorString: "kv.get module error: not a string", errorString: "kv.get module error: not a string",
}, },
@@ -139,7 +145,7 @@ func TestBadKvGet(t *testing.T) {
"module": "test", "module": "test",
}, },
wrappedPayloadModules: map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test", nil),
}, },
errorString: "kv.get key error: not found", errorString: "kv.get key error: not found",
}, },
@@ -151,7 +157,7 @@ func TestBadKvGet(t *testing.T) {
"key": 1, "key": 1,
}, },
wrappedPayloadModules: map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test", nil),
}, },
errorString: "kv.get key error: not a string", 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) b.Fatalf("kv.get failed to create processor: %s", err)
} }
modules := map[string]common.Module{ modules := map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test", map[string]any{
"test": "test",
}),
} }
for b.Loop() { for b.Loop() {
+1 -1
View File
@@ -301,7 +301,7 @@ func BenchmarkKvSet(b *testing.B) {
b.Fatalf("kv.set failed to create processor: %s", err) b.Fatalf("kv.set failed to create processor: %s", err)
} }
modules := map[string]common.Module{ modules := map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test", nil),
} }
count := 0 count := 0
@@ -208,7 +208,7 @@ func TestBadPubSubPublish(t *testing.T) {
"topic": "test", "topic": "test",
}, },
wrappedPayloadModules: map[string]common.Module{ 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", errorString: "pubsub.publish module with id test is not an OutputModule",
}, },
+11 -3
View File
@@ -62,9 +62,10 @@ func (m *TestOutputModule) Id() string {
return m.id return m.id
} }
func NewTestKVModule(id string) *TestKVModule { func NewTestKVModule(id string, presetValues map[string]any) *TestKVModule {
return &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) { 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 { func (m *TestKVModule) Set(key string, value any) error {