Skip to content

Commit

Permalink
Merge pull request #8 from gojekfarm/hermes_561
Browse files Browse the repository at this point in the history
Fix: Pass release name parameter to alabtross for Install API, fix respective tests
  • Loading branch information
buildAI authored Oct 28, 2021
2 parents eb9640b + 58b4632 commit a4c90ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type installRequest struct {
Chart string
Values Values
Flags flags.InstallFlags
Name string
}

// installResponse is the json schema to parse the install api response
Expand Down Expand Up @@ -167,13 +168,15 @@ func (c *HttpClient) Install(ctx context.Context, name string, chart string, val
if err := fl.Valid(); err != nil {
return "", err
}

if name == "" {
return "", errors.New("name cannot be empty")
}
reqBody, err := json.Marshal(&installRequest{
Chart: chart,
Values: values,
Flags: fl,
Name: name,
})
if err != nil {
return "", err
Expand Down
31 changes: 31 additions & 0 deletions api/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ func TestHttpClientInstallAPIOnSuccess(t *testing.T) {
Chart: "testchart",
Values: values,
Flags: fl,
Name: releaseName,
})
assert.NoError(t, err)
apiclient.On("Send", expectedURL, http.MethodPost, bytes.NewBuffer(expectedReq)).Return(httpresponse, apiresponse, nil).Once()
result, err := httpclient.Install(context.Background(), releaseName, "testchart", values, fl)
assert.NoError(t, err)
assert.Equal(t, result, "deployed")
apiclient.AssertExpectations(t)
}

func TestHttpClientInstallAPIOnFailure(t *testing.T) {
Expand Down Expand Up @@ -110,13 +112,42 @@ func TestHttpClientInstallAPIOnFailure(t *testing.T) {
Chart: "",
Values: values,
Flags: fl,
Name: "testrelease",
})
require.NoError(t, err)
apiclient.On("Send", mock.Anything, http.MethodPost, bytes.NewBuffer(jsonRequest)).Return(httpresponse, apiresponse, nil)
result, err := httpclient.Install(context.Background(), "testrelease", "", values, fl)
assert.Error(t, err)
assert.Empty(t, result)
assert.EqualError(t, err, "Install API returned an error: Invalid Request")
apiclient.AssertExpectations(t)
}

func TestHttpClientInstallAPIReturnsErrorWhenNameIsEmptyString(t *testing.T) {
apiclient := new(mockAPIClient)

baseURL, _ := url.ParseRequestURI("http://localhost:8080")

httpclient := &HttpClient{
baseUrl: baseURL,
client: apiclient,
}

values := Values{
"test": "test",
}

fl := flags.InstallFlags{
CommonFlags: flags.CommonFlags{
Namespace: "testnamespace",
KubeContext: "staging",
},
}
result, err := httpclient.Install(context.Background(), "", "", values, fl)
assert.Error(t, err)
assert.Empty(t, result)
assert.EqualError(t, err, "name cannot be empty")
apiclient.AssertExpectations(t)
}

func TestHttpClientUpgradeAPIOnSuccess(t *testing.T) {
Expand Down

0 comments on commit a4c90ad

Please sign in to comment.