mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Merge pull request #3955 from mengqiy/betterresults
Check for empty GKNN when formatting results
This commit is contained in:
@@ -18,7 +18,8 @@ func TestExecute_Result(t *testing.T) {
|
|||||||
p := framework.ResourceListProcessorFunc(func(rl *framework.ResourceList) error {
|
p := framework.ResourceListProcessorFunc(func(rl *framework.ResourceList) error {
|
||||||
err := &framework.Result{
|
err := &framework.Result{
|
||||||
Name: "Incompatible config",
|
Name: "Incompatible config",
|
||||||
Items: []framework.ResultItem{{
|
Items: []framework.ResultItem{
|
||||||
|
{
|
||||||
Message: "bad value for replicas",
|
Message: "bad value for replicas",
|
||||||
Severity: framework.Error,
|
Severity: framework.Error,
|
||||||
ResourceRef: yaml.ResourceMeta{
|
ResourceRef: yaml.ResourceMeta{
|
||||||
@@ -36,7 +37,12 @@ func TestExecute_Result(t *testing.T) {
|
|||||||
Path: "/path/to/deployment.yaml",
|
Path: "/path/to/deployment.yaml",
|
||||||
Index: 0,
|
Index: 0,
|
||||||
},
|
},
|
||||||
}},
|
},
|
||||||
|
{
|
||||||
|
Message: "some error",
|
||||||
|
Severity: framework.Error,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
rl.Result = err
|
rl.Result = err
|
||||||
return err
|
return err
|
||||||
@@ -55,8 +61,9 @@ items:
|
|||||||
replicas: 0
|
replicas: 0
|
||||||
`), Writer: out}
|
`), Writer: out}
|
||||||
err := framework.Execute(p, source)
|
err := framework.Execute(p, source)
|
||||||
assert.EqualError(t, err, "[error] v1/Deployment/default/tester .spec."+
|
assert.EqualError(t, err, `[error] v1/Deployment/default/tester .spec.Replicas: bad value for replicas
|
||||||
"Replicas: bad value for replicas")
|
|
||||||
|
[error] : some error`)
|
||||||
assert.Equal(t, 1, err.(*framework.Result).ExitCode())
|
assert.Equal(t, 1, err.(*framework.Result).ExitCode())
|
||||||
assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
|
assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
|
||||||
kind: ResourceList
|
kind: ResourceList
|
||||||
@@ -84,5 +91,7 @@ results:
|
|||||||
currentValue: "0"
|
currentValue: "0"
|
||||||
suggestedValue: "3"
|
suggestedValue: "3"
|
||||||
file:
|
file:
|
||||||
path: /path/to/deployment.yaml`, strings.TrimSpace(out.String()))
|
path: /path/to/deployment.yaml
|
||||||
|
- message: some error
|
||||||
|
severity: error`, strings.TrimSpace(out.String()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,24 @@ type ResultItem struct {
|
|||||||
// String provides a human-readable message for the result item
|
// String provides a human-readable message for the result item
|
||||||
func (i ResultItem) String() string {
|
func (i ResultItem) String() string {
|
||||||
identifier := i.ResourceRef.GetIdentifier()
|
identifier := i.ResourceRef.GetIdentifier()
|
||||||
idString := strings.Join([]string{identifier.GetAPIVersion(), identifier.GetKind(), identifier.GetNamespace(), identifier.GetName()}, "/")
|
var idStringList []string
|
||||||
|
if identifier.APIVersion != "" {
|
||||||
|
idStringList = append(idStringList, identifier.APIVersion)
|
||||||
|
}
|
||||||
|
if identifier.Kind != "" {
|
||||||
|
idStringList = append(idStringList, identifier.Kind)
|
||||||
|
}
|
||||||
|
if identifier.Namespace != "" {
|
||||||
|
idStringList = append(idStringList, identifier.Namespace)
|
||||||
|
}
|
||||||
|
if identifier.Name != "" {
|
||||||
|
idStringList = append(idStringList, identifier.Name)
|
||||||
|
}
|
||||||
|
if len(idStringList) > 0 {
|
||||||
|
idString := strings.Join(idStringList, "/")
|
||||||
return fmt.Sprintf("[%s] %s %s: %s", i.Severity, idString, i.Field.Path, i.Message)
|
return fmt.Sprintf("[%s] %s %s: %s", i.Severity, idString, i.Field.Path, i.Message)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("[%s] %s: %s", i.Severity, i.Field.Path, i.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// File references a file containing a resource
|
// File references a file containing a resource
|
||||||
|
|||||||
Reference in New Issue
Block a user