master
go 44 lines 918 Bytes
Raw
1 package fxtest
2
3 import (
4 "os"
5
6 logging "github.com/ipfs/go-log/v2"
7 "github.com/ipfs/kubo/core"
8 "github.com/ipfs/kubo/plugin"
9 "go.uber.org/fx"
10 )
11
12 var log = logging.Logger("fxtestplugin")
13
14 var Plugins = []plugin.Plugin{
15 &fxtestPlugin{},
16 }
17
18 // fxtestPlugin is used for testing the fx plugin.
19 // It merely adds an fx option that logs a debug statement, so we can verify that it works in tests.
20 type fxtestPlugin struct{}
21
22 var _ plugin.PluginFx = (*fxtestPlugin)(nil)
23
24 func (p *fxtestPlugin) Name() string {
25 return "fx-test"
26 }
27
28 func (p *fxtestPlugin) Version() string {
29 return "0.1.0"
30 }
31
32 func (p *fxtestPlugin) Init(env *plugin.Environment) error {
33 return nil
34 }
35
36 func (p *fxtestPlugin) Options(info core.FXNodeInfo) ([]fx.Option, error) {
37 opts := info.FXOptions
38 if os.Getenv("TEST_FX_PLUGIN") != "" {
39 opts = append(opts, fx.Invoke(func() {
40 log.Debug("invoked test fx function")
41 }))
42 }
43 return opts, nil
44 }