-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathplugin_test.go
More file actions
94 lines (75 loc) · 2.2 KB
/
plugin_test.go
File metadata and controls
94 lines (75 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package chainsync
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/blinklabs-io/adder/event"
"github.com/blinklabs-io/adder/plugin"
)
func TestPluginRegistration(t *testing.T) {
// Retrieve the plugin entries
plugins := plugin.GetPlugins(
plugin.PluginTypeFilter,
) // Get all registered plugins
// Find the "chainsync" plugin
var p plugin.Plugin
for _, entry := range plugins {
if entry.Name == "chainsync" {
// Create a new instance of the plugin
p = entry.NewFromOptionsFunc()
break
}
}
// Verify that the plugin was found
assert.NotNil(t, p, "Plugin should be registered")
// Verify that the plugin implements the Plugin interface
assert.NotNil(t, p, "Plugin should implement the Plugin interface")
}
func TestPluginStartStop(t *testing.T) {
// Create a new plugin instance
p := NewFromCmdlineOptions()
// Start the plugin
err := p.Start()
assert.NoError(t, err, "Plugin should start without errors")
// Stop the plugin
err = p.Stop()
assert.NoError(t, err, "Plugin should stop without errors")
}
func TestPluginChannels(t *testing.T) {
// Create a new plugin instance
p := NewFromCmdlineOptions()
// Verify that the input channel is not nil
assert.NotNil(t, p.InputChan(), "Input channel should not be nil")
// Verify that the output channel is not nil
assert.NotNil(t, p.OutputChan(), "Output channel should not be nil")
}
func TestPluginEventProcessing(t *testing.T) {
// Create a new plugin instance
p := NewFromCmdlineOptions()
// Start the plugin
err := p.Start()
assert.NoError(t, err, "Plugin should start without errors")
// Create a test event with a TransactionEvent payload
testEvent := event.Event{
Type: "transaction",
Timestamp: time.Now(),
Payload: event.TransactionEvent{},
}
// Send the event to the input channel
p.InputChan() <- testEvent
// Read the event from the output channel
select {
case outputEvent := <-p.OutputChan():
assert.Equal(
t,
testEvent,
outputEvent,
"Output event should match input event",
)
case <-time.After(1 * time.Second):
t.Fatal("Timeout waiting for output event")
}
// Stop the plugin
err = p.Stop()
assert.NoError(t, err, "Plugin should stop without errors")
}