mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-10-05 16:17:12 +08:00
constructor: allow nil options
This can make it significantly easier to configure libp2p with optional options.
This commit is contained in:
23
config/config_test.go
Normal file
23
config/config_test.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user