-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplugin_test.go
More file actions
57 lines (43 loc) · 1.4 KB
/
Copy pathplugin_test.go
File metadata and controls
57 lines (43 loc) · 1.4 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
package sqs
import (
"log/slog"
"os"
"testing"
"github.com/roadrunner-server/errors"
"github.com/stretchr/testify/require"
)
type testLogger struct{}
func (*testLogger) NamedLogger(string) *slog.Logger {
return slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}))
}
// testCfg reports the listed sections as present and nothing else.
type testCfg struct {
sections map[string]struct{}
}
func newCfg(sections ...string) *testCfg {
c := &testCfg{sections: make(map[string]struct{}, len(sections))}
for _, s := range sections {
c.sections[s] = struct{}{}
}
return c
}
func (*testCfg) UnmarshalKey(string, any) error { return nil }
func (c *testCfg) Has(name string) bool {
_, ok := c.sections[name]
return ok
}
func TestPluginName(t *testing.T) {
require.Equal(t, "sqs", (&Plugin{}).Name())
}
// TestPluginInit covers the enable rule: either section on its own is enough,
// and the plugin only disables itself when neither is configured.
func TestPluginInit(t *testing.T) {
require.NoError(t, (&Plugin{}).Init(&testLogger{}, newCfg("sqs")))
require.NoError(t, (&Plugin{}).Init(&testLogger{}, newCfg("jobs")))
err := (&Plugin{}).Init(&testLogger{}, newCfg("http"))
require.Error(t, err)
require.True(t, errors.Is(errors.Disabled, err), "expected a Disabled error, got %v", err)
}
func TestCollectsTracer(t *testing.T) {
require.Len(t, (&Plugin{}).Collects(), 1)
}