Print type representation on errors when checking parameter types

Signed-off-by: Ferran Rodenas <frodenas@gmail.com>
This commit is contained in:
Ferran Rodenas 2017-10-27 10:41:15 +02:00 committed by Ferran Rodenas
parent a29b01bcd2
commit c73518d1a8
2 changed files with 14 additions and 14 deletions

View File

@ -50,15 +50,15 @@ func (s PodDisruptionBudgetV1Generator) Generate(params map[string]interface{})
}
name, isString := params["name"].(string)
if !isString {
return nil, fmt.Errorf("expected string, found %v for 'name'", params["name"])
return nil, fmt.Errorf("expected string, found %T for 'name'", params["name"])
}
minAvailable, isString := params["min-available"].(string)
if !isString {
return nil, fmt.Errorf("expected string, found %v for 'min-available'", params["min-available"])
return nil, fmt.Errorf("expected string, found %T for 'min-available'", params["min-available"])
}
selector, isString := params["selector"].(string)
if !isString {
return nil, fmt.Errorf("expected string, found %v for 'selector'", params["selector"])
return nil, fmt.Errorf("expected string, found %T for 'selector'", params["selector"])
}
delegate := &PodDisruptionBudgetV1Generator{Name: name, MinAvailable: minAvailable, Selector: selector}
return delegate.StructuredGenerate()
@ -134,22 +134,22 @@ func (s PodDisruptionBudgetV2Generator) Generate(params map[string]interface{})
name, isString := params["name"].(string)
if !isString {
return nil, fmt.Errorf("expected string, found %v for 'name'", params["name"])
return nil, fmt.Errorf("expected string, found %T for 'name'", params["name"])
}
minAvailable, isString := params["min-available"].(string)
if !isString {
return nil, fmt.Errorf("expected string, found %v for 'min-available'", params["min-available"])
return nil, fmt.Errorf("expected string, found %T for 'min-available'", params["min-available"])
}
maxUnavailable, isString := params["max-unavailable"].(string)
if !isString {
return nil, fmt.Errorf("expected string, found %v for 'max-unavailable'", params["max-unavailable"])
return nil, fmt.Errorf("expected string, found %T for 'max-unavailable'", params["max-unavailable"])
}
selector, isString := params["selector"].(string)
if !isString {
return nil, fmt.Errorf("expected string, found %v for 'selector'", params["selector"])
return nil, fmt.Errorf("expected string, found %T for 'selector'", params["selector"])
}
delegate := &PodDisruptionBudgetV2Generator{Name: name, MinAvailable: minAvailable, MaxUnavailable: maxUnavailable, Selector: selector}
return delegate.StructuredGenerate()

View File

@ -78,7 +78,7 @@ func TestPodDisruptionBudgetV1Generate(t *testing.T) {
"min-available": minAvailable,
"selector": selector,
},
expectErrMsg: "expected string, found 1 for 'name'",
expectErrMsg: "expected string, found int for 'name'",
},
"test-missing-min-available-param": {
params: map[string]interface{}{
@ -109,7 +109,7 @@ func TestPodDisruptionBudgetV1Generate(t *testing.T) {
"min-available": 1,
"selector": selector,
},
expectErrMsg: "expected string, found 1 for 'min-available'",
expectErrMsg: "expected string, found int for 'min-available'",
},
"test-missing-selector-param": {
params: map[string]interface{}{
@ -132,7 +132,7 @@ func TestPodDisruptionBudgetV1Generate(t *testing.T) {
"min-available": minAvailable,
"selector": 1,
},
expectErrMsg: "expected string, found 1 for 'selector'",
expectErrMsg: "expected string, found int for 'selector'",
},
}
@ -233,7 +233,7 @@ func TestPodDisruptionBudgetV2Generate(t *testing.T) {
"max-unavailable": "",
"selector": selector,
},
expectErrMsg: "expected string, found 1 for 'name'",
expectErrMsg: "expected string, found int for 'name'",
},
"test-missing-min-available-param": {
params: map[string]interface{}{
@ -250,7 +250,7 @@ func TestPodDisruptionBudgetV2Generate(t *testing.T) {
"max-unavailable": "",
"selector": selector,
},
expectErrMsg: "expected string, found 1 for 'min-available'",
expectErrMsg: "expected string, found int for 'min-available'",
},
"test-missing-max-available-param": {
params: map[string]interface{}{
@ -267,7 +267,7 @@ func TestPodDisruptionBudgetV2Generate(t *testing.T) {
"max-unavailable": 1,
"selector": selector,
},
expectErrMsg: "expected string, found 1 for 'max-unavailable'",
expectErrMsg: "expected string, found int for 'max-unavailable'",
},
"test-blank-min-available-max-unavailable-param": {
params: map[string]interface{}{
@ -311,7 +311,7 @@ func TestPodDisruptionBudgetV2Generate(t *testing.T) {
"max-unavailable": "",
"selector": 1,
},
expectErrMsg: "expected string, found 1 for 'selector'",
expectErrMsg: "expected string, found int for 'selector'",
},
}