Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InitWithReset - rely on previously updated flags #7598

Merged
merged 8 commits into from
Oct 22, 2020
8 changes: 7 additions & 1 deletion shared/featureconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ func Init(c *Flags) {

// InitWithReset sets the global config and returns function that is used to reset configuration.
func InitWithReset(c *Flags) func() {
var prevConfig Flags
if featureConfig != nil {
prevConfig = *featureConfig
} else {
prevConfig = Flags{}
}
resetFunc := func() {
Init(&Flags{})
Init(&prevConfig)
}
Init(c)
return resetFunc
Expand Down
22 changes: 22 additions & 0 deletions shared/featureconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestInitFeatureConfig(t *testing.T) {
defer Init(&Flags{})
cfg := &Flags{
MedallaTestnet: true,
}
Expand All @@ -21,6 +22,27 @@ func TestInitFeatureConfig(t *testing.T) {
Init(cfg)
}

func TestInitWithReset(t *testing.T) {
defer Init(&Flags{})
Init(&Flags{
OnyxTestnet: true,
})
assert.Equal(t, false, Get().AltonaTestnet)
assert.Equal(t, true, Get().OnyxTestnet)

// Overwrite previously set value (value that didn't come by default).
resetCfg := InitWithReset(&Flags{
OnyxTestnet: false,
})
assert.Equal(t, false, Get().AltonaTestnet)
assert.Equal(t, false, Get().OnyxTestnet)

// Reset must get to previously set configuration (not to default config values).
resetCfg()
assert.Equal(t, false, Get().AltonaTestnet)
assert.Equal(t, true, Get().OnyxTestnet)
}

func TestConfigureBeaconConfig(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
Expand Down