-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix the invalid kube yaml causing panic issue #171
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||
// | ||||
// Copyright 2022 Red Hat, Inc. | ||||
// Copyright 2022-2023 Red Hat, Inc. | ||||
// | ||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||
// you may not use this file except in compliance with the License. | ||||
|
@@ -72,7 +72,9 @@ func TestReadAndParseKubernetesYaml(t *testing.T) { | |||
name string | ||||
src YamlSrc | ||||
fs *afero.Afero | ||||
testParseYamlOnly bool | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where are we setting this? We are using it but i dont see it being set a value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. library/pkg/devfile/parser/reader_test.go Line 177 in 88946b6
|
||||
wantErr bool | ||||
wantParserErr bool | ||||
wantDeploymentNames []string | ||||
wantServiceNames []string | ||||
wantRouteNames []string | ||||
|
@@ -111,6 +113,14 @@ func TestReadAndParseKubernetesYaml(t *testing.T) { | |||
fs: nil, | ||||
wantErr: true, | ||||
}, | ||||
{ | ||||
name: "Bad Path", | ||||
src: YamlSrc{ | ||||
Path: "$%^&", | ||||
}, | ||||
fs: &fs, | ||||
wantErr: true, | ||||
}, | ||||
{ | ||||
name: "Read the YAML from the Data", | ||||
src: YamlSrc{ | ||||
|
@@ -147,45 +157,54 @@ func TestReadAndParseKubernetesYaml(t *testing.T) { | |||
fs: nil, | ||||
wantErr: true, | ||||
}, | ||||
{ | ||||
name: "Invalid kube yaml Data", | ||||
src: YamlSrc{ | ||||
Data: []byte("invalidyaml"), | ||||
}, | ||||
fs: nil, | ||||
wantParserErr: true, | ||||
}, | ||||
} | ||||
|
||||
for _, tt := range tests { | ||||
t.Run(tt.name, func(t *testing.T) { | ||||
values, err := ReadKubernetesYaml(tt.src, tt.fs) | ||||
if (err != nil) != tt.wantErr { | ||||
t.Errorf("unexpected error: %v", err) | ||||
t.Errorf("unexpected error: %v, wantErr: %v", err, tt.wantErr) | ||||
return | ||||
} | ||||
|
||||
for _, value := range values { | ||||
kubernetesMap := value.(map[string]interface{}) | ||||
|
||||
kind := kubernetesMap["kind"] | ||||
metadataMap := kubernetesMap["metadata"].(map[string]interface{}) | ||||
name := metadataMap["name"] | ||||
|
||||
switch kind { | ||||
case "Deployment": | ||||
assert.Contains(t, tt.wantDeploymentNames, name) | ||||
case "Service": | ||||
assert.Contains(t, tt.wantServiceNames, name) | ||||
case "Route": | ||||
assert.Contains(t, tt.wantRouteNames, name) | ||||
case "Ingress": | ||||
assert.Contains(t, tt.wantIngressNames, name) | ||||
default: | ||||
assert.Contains(t, tt.wantOtherNames, name) | ||||
if tt.testParseYamlOnly { | ||||
for _, value := range values { | ||||
kubernetesMap := value.(map[string]interface{}) | ||||
|
||||
kind := kubernetesMap["kind"] | ||||
metadataMap := kubernetesMap["metadata"].(map[string]interface{}) | ||||
name := metadataMap["name"] | ||||
|
||||
switch kind { | ||||
case "Deployment": | ||||
assert.Contains(t, tt.wantDeploymentNames, name) | ||||
case "Service": | ||||
assert.Contains(t, tt.wantServiceNames, name) | ||||
case "Route": | ||||
assert.Contains(t, tt.wantRouteNames, name) | ||||
case "Ingress": | ||||
assert.Contains(t, tt.wantIngressNames, name) | ||||
default: | ||||
assert.Contains(t, tt.wantOtherNames, name) | ||||
} | ||||
} | ||||
} | ||||
|
||||
if len(values) > 0 { | ||||
resources, err := ParseKubernetesYaml(values) | ||||
if err != nil { | ||||
t.Error(err) | ||||
if (err != nil) != tt.wantParserErr { | ||||
t.Errorf("unexpected error: %v, wantErr: %v", err, tt.wantParserErr) | ||||
return | ||||
} | ||||
|
||||
if reflect.DeepEqual(resources, KubernetesResources{}) { | ||||
if reflect.DeepEqual(resources, KubernetesResources{}) && !tt.wantParserErr { | ||||
t.Error("Kubernetes resources is empty, expected to contain some resources") | ||||
} else { | ||||
deployments := resources.Deployments | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated