Skip to content

Commit

Permalink
Fix panic when Affinity.New receives a nil config
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Oct 2, 2023
1 parent 7dd5429 commit 3146c52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugin/impl/affinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type Affinity struct {

// New creates a new Affinity instance with the given config.
func (a *Affinity) New(config *ucfgwrap.Config) (plugin.Checker, error) {
if config == nil {
return &Affinity{}, nil
}
conf := struct {
MinOperational int `config:"minOperational"`
}{}
Expand Down
7 changes: 7 additions & 0 deletions plugin/impl/affinity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ var _ = Describe("The Affinity plugin", func() {
Expect(plugin.(*Affinity).MinOperational).To(Equal(0))
})

It("can initialize when config is nil", func() {
var base Affinity
plugin, err := base.New(nil)
Expect(err).To(Succeed())
Expect(plugin.(*Affinity).MinOperational).To(Equal(0))
})

})

0 comments on commit 3146c52

Please sign in to comment.