constructor: allow nil options

This can make it significantly easier to configure libp2p with optional options.
This commit is contained in:
Steven Allen
2019-04-17 16:20:02 -07:00
parent 213863abbc
commit cff9cb577c
4 changed files with 54 additions and 0 deletions

23
config/config_test.go Normal file
View File

@@ -0,0 +1,23 @@
package config
import (
"testing"
)
func TestNilOption(t *testing.T) {
var cfg Config
optsRun := 0
opt := func(c *Config) error {
optsRun++
return nil
}
if err := cfg.Apply(nil); err != nil {
t.Fatal(err)
}
if err := cfg.Apply(opt, nil, nil, opt, opt, nil); err != nil {
t.Fatal(err)
}
if optsRun != 3 {
t.Fatalf("expected to have handled 3 options, handled %d", optsRun)
}
}