mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-08-20 05:28:58 +00:00
add ability to set test kv properties
This commit is contained in:
@@ -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",
|
||||
},
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
|
||||
+11
-3
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user