Skip to content

Commit

Permalink
Fix tests and make sure deprecated flags work
Browse files Browse the repository at this point in the history
Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
  • Loading branch information
gouthamve committed Nov 17, 2018
1 parent a368e7f commit 7229f86
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
9 changes: 7 additions & 2 deletions cmd/agent/app/reporter/tchannel/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ func (b *Builder) InitFromViper(v *viper.Viper, logger *zap.Logger) *Builder {
if len(v.GetString(tchannelPrefix+hostPort)) > 0 {
b.CollectorHostPorts = strings.Split(v.GetString(tchannelPrefix+hostPort), ",")
}
b.DiscoveryMinPeers = v.GetInt(tchannelPrefix + discoveryMinPeers)
b.ConnCheckTimeout = v.GetDuration(tchannelPrefix + discoveryConnCheckTimeout)

if v.GetInt(tchannelPrefix+discoveryMinPeers) != defaultMinPeers {
b.DiscoveryMinPeers = v.GetInt(tchannelPrefix + discoveryMinPeers)
}
if v.GetDuration(tchannelPrefix+discoveryConnCheckTimeout) != defaultConnCheckTimeout {
b.ConnCheckTimeout = v.GetDuration(tchannelPrefix + discoveryConnCheckTimeout)
}
b.ReportTimeout = v.GetDuration(tchannelPrefix + reportTimeout)
return b
}
23 changes: 13 additions & 10 deletions cmd/agent/app/reporter/tchannel/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ import (
)

func TestBingFlags(t *testing.T) {
v := viper.New()
command := cobra.Command{}
flags := &flag.FlagSet{}
AddFlags(flags)
command.PersistentFlags().AddGoFlagSet(flags)
v.BindPFlags(command.PersistentFlags())

tests := []struct {
flags []string
builder Builder
Expand All @@ -47,14 +40,14 @@ func TestBingFlags(t *testing.T) {
},
{flags: []string{
"--collector.host-port=1.2.3.4:555,1.2.3.4:666",
"--discovery.min-peers=42",
"--discovery.min-peers=45",
"--discovery.conn-check-timeout=85s",
},
builder: Builder{ConnCheckTimeout: time.Second * 85, ReportTimeout: defaultReportTimeout, DiscoveryMinPeers: 42, CollectorHostPorts: []string{"1.2.3.4:555", "1.2.3.4:666"}},
builder: Builder{ConnCheckTimeout: time.Second * 85, ReportTimeout: defaultReportTimeout, DiscoveryMinPeers: 45, CollectorHostPorts: []string{"1.2.3.4:555", "1.2.3.4:666"}},
},
{flags: []string{
"--collector.host-port=1.2.3.4:555,1.2.3.4:666",
"--discovery.min-peers=42",
"--discovery.min-peers=46",
"--discovery.conn-check-timeout=85s",
"--reporter.tchannel.host-port=1.2.3.4:5556,1.2.3.4:6667",
"--reporter.tchannel.discovery.min-peers=43",
Expand All @@ -64,6 +57,16 @@ func TestBingFlags(t *testing.T) {
},
}
for _, test := range tests {
// Reset flags every iteration.
v := viper.New()
command := cobra.Command{}

flags := &flag.FlagSet{}
AddFlags(flags)
command.ResetFlags()
command.PersistentFlags().AddGoFlagSet(flags)
v.BindPFlags(command.PersistentFlags())

err := command.ParseFlags(test.flags)
require.NoError(t, err)
b := Builder{}
Expand Down

0 comments on commit 7229f86

Please sign in to comment.