Print type representation on errors when checking parameter types
Signed-off-by: Ferran Rodenas <frodenas@gmail.com>
This commit is contained in:
committed by
Ferran Rodenas
parent
a29b01bcd2
commit
c73518d1a8
@@ -50,15 +50,15 @@ func (s PodDisruptionBudgetV1Generator) Generate(params map[string]interface{})
|
|||||||
}
|
}
|
||||||
name, isString := params["name"].(string)
|
name, isString := params["name"].(string)
|
||||||
if !isString {
|
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)
|
minAvailable, isString := params["min-available"].(string)
|
||||||
if !isString {
|
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)
|
selector, isString := params["selector"].(string)
|
||||||
if !isString {
|
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}
|
delegate := &PodDisruptionBudgetV1Generator{Name: name, MinAvailable: minAvailable, Selector: selector}
|
||||||
return delegate.StructuredGenerate()
|
return delegate.StructuredGenerate()
|
||||||
@@ -134,22 +134,22 @@ func (s PodDisruptionBudgetV2Generator) Generate(params map[string]interface{})
|
|||||||
|
|
||||||
name, isString := params["name"].(string)
|
name, isString := params["name"].(string)
|
||||||
if !isString {
|
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)
|
minAvailable, isString := params["min-available"].(string)
|
||||||
if !isString {
|
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)
|
maxUnavailable, isString := params["max-unavailable"].(string)
|
||||||
if !isString {
|
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)
|
selector, isString := params["selector"].(string)
|
||||||
if !isString {
|
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}
|
delegate := &PodDisruptionBudgetV2Generator{Name: name, MinAvailable: minAvailable, MaxUnavailable: maxUnavailable, Selector: selector}
|
||||||
return delegate.StructuredGenerate()
|
return delegate.StructuredGenerate()
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func TestPodDisruptionBudgetV1Generate(t *testing.T) {
|
|||||||
"min-available": minAvailable,
|
"min-available": minAvailable,
|
||||||
"selector": selector,
|
"selector": selector,
|
||||||
},
|
},
|
||||||
expectErrMsg: "expected string, found 1 for 'name'",
|
expectErrMsg: "expected string, found int for 'name'",
|
||||||
},
|
},
|
||||||
"test-missing-min-available-param": {
|
"test-missing-min-available-param": {
|
||||||
params: map[string]interface{}{
|
params: map[string]interface{}{
|
||||||
@@ -109,7 +109,7 @@ func TestPodDisruptionBudgetV1Generate(t *testing.T) {
|
|||||||
"min-available": 1,
|
"min-available": 1,
|
||||||
"selector": selector,
|
"selector": selector,
|
||||||
},
|
},
|
||||||
expectErrMsg: "expected string, found 1 for 'min-available'",
|
expectErrMsg: "expected string, found int for 'min-available'",
|
||||||
},
|
},
|
||||||
"test-missing-selector-param": {
|
"test-missing-selector-param": {
|
||||||
params: map[string]interface{}{
|
params: map[string]interface{}{
|
||||||
@@ -132,7 +132,7 @@ func TestPodDisruptionBudgetV1Generate(t *testing.T) {
|
|||||||
"min-available": minAvailable,
|
"min-available": minAvailable,
|
||||||
"selector": 1,
|
"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": "",
|
"max-unavailable": "",
|
||||||
"selector": selector,
|
"selector": selector,
|
||||||
},
|
},
|
||||||
expectErrMsg: "expected string, found 1 for 'name'",
|
expectErrMsg: "expected string, found int for 'name'",
|
||||||
},
|
},
|
||||||
"test-missing-min-available-param": {
|
"test-missing-min-available-param": {
|
||||||
params: map[string]interface{}{
|
params: map[string]interface{}{
|
||||||
@@ -250,7 +250,7 @@ func TestPodDisruptionBudgetV2Generate(t *testing.T) {
|
|||||||
"max-unavailable": "",
|
"max-unavailable": "",
|
||||||
"selector": selector,
|
"selector": selector,
|
||||||
},
|
},
|
||||||
expectErrMsg: "expected string, found 1 for 'min-available'",
|
expectErrMsg: "expected string, found int for 'min-available'",
|
||||||
},
|
},
|
||||||
"test-missing-max-available-param": {
|
"test-missing-max-available-param": {
|
||||||
params: map[string]interface{}{
|
params: map[string]interface{}{
|
||||||
@@ -267,7 +267,7 @@ func TestPodDisruptionBudgetV2Generate(t *testing.T) {
|
|||||||
"max-unavailable": 1,
|
"max-unavailable": 1,
|
||||||
"selector": selector,
|
"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": {
|
"test-blank-min-available-max-unavailable-param": {
|
||||||
params: map[string]interface{}{
|
params: map[string]interface{}{
|
||||||
@@ -311,7 +311,7 @@ func TestPodDisruptionBudgetV2Generate(t *testing.T) {
|
|||||||
"max-unavailable": "",
|
"max-unavailable": "",
|
||||||
"selector": 1,
|
"selector": 1,
|
||||||
},
|
},
|
||||||
expectErrMsg: "expected string, found 1 for 'selector'",
|
expectErrMsg: "expected string, found int for 'selector'",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user