-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add the standard flag --replication-factor
Previously varlogadm and varlogmr defined the flag for replication factor, respectively, which made strings for the flag different. This change adds a new standard flag, `--replication-factor`. It also sets the type of replication factor to an integer.
- Loading branch information
Showing
11 changed files
with
96 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package flags | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
const ( | ||
CategoryCluster = "Cluster:" | ||
|
||
DefaultReplicationFactor = 1 | ||
) | ||
|
||
var ( | ||
ReplicationFactor = &cli.IntFlag{ | ||
Name: "replication-factor", | ||
Category: CategoryCluster, | ||
EnvVars: []string{"REPLICATION_FACTOR"}, | ||
Value: DefaultReplicationFactor, | ||
Action: func(_ *cli.Context, value int) error { | ||
if value <= 0 { | ||
return fmt.Errorf("invalid value \"%d\" for flag --replication-factor", value) | ||
} | ||
return nil | ||
}, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package flags | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func TestReplicationFactor(t *testing.T) { | ||
tcs := []struct { | ||
name string | ||
args []string | ||
ok bool | ||
}{ | ||
{ | ||
name: "replication_factor=1", | ||
args: []string{"test", "--replication-factor=1"}, | ||
ok: true, | ||
}, | ||
{ | ||
name: "replication_factor=0", | ||
args: []string{"test", "--replication-factor=0"}, | ||
ok: false, | ||
}, | ||
{ | ||
name: "replication_factor=-1", | ||
args: []string{"test", "--replication-factor=-1"}, | ||
ok: false, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
app := &cli.App{ | ||
Name: "test", | ||
Flags: []cli.Flag{ | ||
ReplicationFactor, | ||
}, | ||
Writer: io.Discard, | ||
} | ||
err := app.Run(tc.args) | ||
if !tc.ok { | ||
require.Error(t, err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters