mirror of https://github.com/grafana/loki
avoid mutating config while parsing -config.file (#2392)
* avoid mutating config while parsing -config.file * minimal config mutation test case * logcli local query config file compatpull/2471/head
parent
cb20afaa26
commit
7530bf6def
@ -0,0 +1,33 @@ |
||||
package cfg |
||||
|
||||
import ( |
||||
"flag" |
||||
"testing" |
||||
|
||||
"github.com/cortexproject/cortex/pkg/util/flagext" |
||||
"github.com/stretchr/testify/require" |
||||
) |
||||
|
||||
type testCfg struct { |
||||
v int |
||||
} |
||||
|
||||
func (cfg *testCfg) RegisterFlags(f *flag.FlagSet) { |
||||
cfg.v++ |
||||
} |
||||
|
||||
func (cfg *testCfg) Clone() flagext.Registerer { |
||||
return func(cfg testCfg) flagext.Registerer { |
||||
return &cfg |
||||
}(*cfg) |
||||
} |
||||
|
||||
func TestYAMLFlagDoesNotMutate(t *testing.T) { |
||||
cfg := &testCfg{} |
||||
err := YAMLFlag(nil, "something")(cfg) |
||||
require.Nil(t, err) |
||||
require.Equal(t, 0, cfg.v) |
||||
|
||||
cfg.RegisterFlags(nil) |
||||
require.Equal(t, 1, cfg.v) |
||||
} |
||||
Loading…
Reference in new issue