Deployment: preserve availability when maxUnavailability is not 100%

This commit is contained in:
mqliang
2016-02-25 13:03:47 +08:00
parent 9a4e3f8470
commit 06d57ec7f4
4 changed files with 27 additions and 7 deletions

View File

@@ -114,6 +114,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
tests := []struct {
input IntOrString
total int
roundUp bool
expectErr bool
expectVal int
}{
@@ -125,9 +126,24 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
{
input: FromString("90%"),
total: 100,
roundUp: true,
expectErr: false,
expectVal: 90,
},
{
input: FromString("90%"),
total: 95,
roundUp: true,
expectErr: false,
expectVal: 86,
},
{
input: FromString("90%"),
total: 95,
roundUp: false,
expectErr: false,
expectVal: 85,
},
{
input: FromString("%"),
expectErr: true,
@@ -144,7 +160,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
for i, test := range tests {
t.Logf("test case %d", i)
value, err := GetValueFromIntOrPercent(&test.input, test.total)
value, err := GetValueFromIntOrPercent(&test.input, test.total, test.roundUp)
if test.expectErr && err == nil {
t.Errorf("expected error, but got none")
continue
@@ -154,7 +170,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
continue
}
if test.expectVal != value {
t.Errorf("expected %v, but got %v", test.expectErr, value)
t.Errorf("expected %v, but got %v", test.expectVal, value)
}
}
}