-
Notifications
You must be signed in to change notification settings - Fork 593
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
Bug 1803941: close helm request on error #4088
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
akashshinde:fix-odc-2871-helm-err-response
Feb 19, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
package handlers | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
|
||
"helm.sh/helm/v3/pkg/action" | ||
"helm.sh/helm/v3/pkg/release" | ||
|
||
"github.com/openshift/console/pkg/auth" | ||
) | ||
|
||
var fakeReleaseList = []*release.Release{ | ||
{ | ||
Name: "Test", | ||
}, | ||
} | ||
|
||
var fakeRelease = release.Release{ | ||
Name: "Test", | ||
} | ||
|
||
var fakeReleaseManifest = "manifest-data" | ||
|
||
func fakeHelmHandler() helmHandlers { | ||
return helmHandlers{ | ||
getActionConfigurations: getFakeActionConfigurations, | ||
} | ||
} | ||
|
||
func fakeInstallChart(mockedRelease *release.Release, err error) func(ns string, name string, url string, values map[string]interface{}, conf *action.Configuration) (*release.Release, error) { | ||
return func(ns string, name string, url string, values map[string]interface{}, conf *action.Configuration) (r *release.Release, er error) { | ||
return mockedRelease, err | ||
} | ||
} | ||
|
||
func fakeListReleases(mockedReleases []*release.Release, err error) func(conf *action.Configuration) ([]*release.Release, error) { | ||
return func(conf *action.Configuration) (releases []*release.Release, er error) { | ||
return mockedReleases, err | ||
} | ||
} | ||
|
||
func fakeGetManifest(mockedManifest string, err error) func(name string, url string, values map[string]interface{}, conf *action.Configuration) (string, error) { | ||
return func(name string, url string, values map[string]interface{}, conf *action.Configuration) (r string, er error) { | ||
return mockedManifest, err | ||
} | ||
} | ||
|
||
func getFakeActionConfigurations(string, string, string, *http.RoundTripper) *action.Configuration { | ||
return &action.Configuration{} | ||
} | ||
|
||
func TestHelmHandlers_HandleHelmList(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
expectedResponse string | ||
releaseList []*release.Release | ||
error | ||
httpStatusCode int | ||
}{ | ||
{ | ||
name: "Error occurred at listing releases", | ||
error: errors.New("unknown error occurred"), | ||
httpStatusCode: http.StatusBadGateway, | ||
expectedResponse: `{"error":"Failed to list helm releases: unknown error occurred"}`, | ||
}, | ||
{ | ||
name: "Return releases serialized in JSON format", | ||
expectedResponse: `[{"name":"Test"}]`, | ||
releaseList: fakeReleaseList, | ||
httpStatusCode: http.StatusOK, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
handlers := fakeHelmHandler() | ||
handlers.listReleases = fakeListReleases(tt.releaseList, tt.error) | ||
|
||
request := httptest.NewRequest("", "/foo", strings.NewReader("{}")) | ||
response := httptest.NewRecorder() | ||
|
||
handlers.HandleHelmList(&auth.User{}, response, request) | ||
if response.Code != tt.httpStatusCode { | ||
t.Errorf("response code should be %v but got %v", tt.httpStatusCode, response.Code) | ||
} | ||
if response.Header().Get("Content-Type") != "application/json" { | ||
t.Errorf("content type should be application/json but got %s", response.Header().Get("Content-Type")) | ||
} | ||
if response.Body.String() != tt.expectedResponse { | ||
t.Errorf("response body not matching expected is %s and received is %s", tt.expectedResponse, response.Body.String()) | ||
} | ||
|
||
}) | ||
} | ||
} | ||
|
||
func TestHelmHandlers_HandleHelmInstall(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
expectedResponse string | ||
installedRelease release.Release | ||
error | ||
httpStatusCode int | ||
}{ | ||
{ | ||
name: "Error occurred", | ||
expectedResponse: `{"error":"Failed to install helm chart: Chart path is invalid"}`, | ||
error: errors.New("Chart path is invalid"), | ||
httpStatusCode: http.StatusBadGateway, | ||
}, | ||
{ | ||
name: "Successful install returns release info in JSON format", | ||
installedRelease: fakeRelease, | ||
httpStatusCode: http.StatusOK, | ||
expectedResponse: `{"name":"Test"}`, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
handlers := fakeHelmHandler() | ||
handlers.installChart = fakeInstallChart(&tt.installedRelease, tt.error) | ||
|
||
request := httptest.NewRequest("", "/foo", strings.NewReader("{}")) | ||
response := httptest.NewRecorder() | ||
|
||
handlers.HandleHelmInstall(&auth.User{}, response, request) | ||
if response.Code != tt.httpStatusCode { | ||
t.Errorf("response code should be %v but got %v", tt.httpStatusCode, response.Code) | ||
} | ||
if response.Header().Get("Content-Type") != "application/json" { | ||
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. not sure why |
||
t.Errorf("content type should be application/json but got %s", response.Header().Get("Content-Type")) | ||
} | ||
if response.Body.String() != tt.expectedResponse { | ||
t.Errorf("response body not matching expected is %s and received is %s", tt.expectedResponse, response.Body.String()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestHelmHandlers_HandleHelmRenderManifest(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
expectedResponse string | ||
expectedManifest string | ||
expectedContentType string | ||
error | ||
httpStatusCode int | ||
}{ | ||
{ | ||
name: "Error occurred", | ||
error: errors.New("Chart path is invalid"), | ||
expectedResponse: `{"error":"Failed to render manifests: Chart path is invalid"}`, | ||
httpStatusCode: http.StatusBadGateway, | ||
expectedContentType: "application/json", | ||
}, | ||
{ | ||
name: "Return manifest in yaml format", | ||
expectedResponse: fakeReleaseManifest, | ||
expectedManifest: fakeReleaseManifest, | ||
httpStatusCode: http.StatusOK, | ||
expectedContentType: "text/yaml", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
handlers := fakeHelmHandler() | ||
handlers.renderManifests = fakeGetManifest(tt.expectedManifest, tt.error) | ||
|
||
request := httptest.NewRequest("", "/foo", strings.NewReader("{}")) | ||
response := httptest.NewRecorder() | ||
|
||
handlers.HandleHelmRenderManifests(&auth.User{}, response, request) | ||
|
||
if response.Code != tt.httpStatusCode { | ||
t.Errorf("response code should be %v but got %v", tt.httpStatusCode, response.Code) | ||
} | ||
if response.Header().Get("Content-Type") != tt.expectedContentType { | ||
t.Errorf("content type should be %s but got %s", tt.expectedContentType, response.Header().Get("Content-Type")) | ||
} | ||
if response.Body.String() != tt.expectedResponse { | ||
t.Errorf("response body not matching expected is %s and received is %s", tt.expectedResponse, response.Body.String()) | ||
} | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ export GOFLAGS="-mod=vendor" | |
# Invoke ./cover for HTML output | ||
COVER=${COVER:-"-cover"} | ||
|
||
TESTABLE="pkg/auth pkg/proxy pkg/server" | ||
TESTABLE="pkg/auth pkg/proxy pkg/server pkg/helm/actions pkg/helm/handlers" | ||
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. @pedjak want to open a follow where we change this to |
||
FORMATTABLE="${TESTABLE} cmd/bridge pkg/version" | ||
|
||
# user has not provided PKG override | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you want this to semi-resemble a real response?
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.
not necessarily -just want to check if the provided input generate appropriate output.