File tree Expand file tree Collapse file tree 2 files changed +17
-12
lines changed Expand file tree Collapse file tree 2 files changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -29,19 +29,20 @@ func PrependPlugin(p plugin.Plugin) Option {
2929// ReplacePlugin replaces any existing plugin with a matching plugin name
3030func ReplacePlugin (p plugin.Plugin ) Option {
3131 return func (cfg * config.Config , plugins * []plugin.Plugin ) {
32- if plugins != nil {
33- found := false
34- ps := * plugins
35- for i , o := range ps {
36- if p .Name () == o .Name () {
37- ps [i ] = p
38- found = true
39- }
40- }
41- if ! found {
42- ps = append (ps , p )
32+ if plugins == nil {
33+ return
34+ }
35+ found := false
36+ ps := * plugins
37+ for i , o := range ps {
38+ if p .Name () == o .Name () {
39+ ps [i ] = p
40+ found = true
4341 }
44- * plugins = ps
4542 }
43+ if ! found {
44+ ps = append (ps , p )
45+ }
46+ * plugins = ps
4647 }
4748}
Original file line number Diff line number Diff line change @@ -53,6 +53,10 @@ func TestReplacePlugin(t *testing.T) {
5353 require .EqualValues (t , resolvergen .New (), pg [1 ])
5454 require .EqualValues (t , expectedPlugin , pg [2 ])
5555 })
56+
57+ t .Run ("do nothing if plugins is nil" , func (t * testing.T ) {
58+ ReplacePlugin (& testPlugin {})(config .DefaultConfig (), nil )
59+ })
5660}
5761
5862func TestPrependPlugin (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments