Skip to content

Commit

Permalink
dco sign
Browse files Browse the repository at this point in the history
Signed-off-by: Friedrich Albert Kyuri <friedrichak42@gmail.com>
  • Loading branch information
Friedrich Albert Kyuri committed Mar 18, 2022
1 parent 8c85751 commit cb53667
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- **Azure Queue:** Don't call Azure queue GetProperties API unnecessarily ([#2613](https://github.com/kedacore/keda/pull/2613))
- **Datadog Scaler:** Validate query to contain `{` to prevent panic on invalid query ([#2625](https://github.com/kedacore/keda/issues/2625))
- **Kafka Scaler** Make "disable" a valid value for tls auth parameter ([#2608](https://github.com/kedacore/keda/issues/2608))
- **Metric API Scaler:** Improve error handling on not-ok response ([#2317](https://github.com/kedacore/keda/issues/2317))
- **RabbitMQ Scaler:** Include `vhost` for RabbitMQ when retrieving queue info with `useRegex` ([#2498](https://github.com/kedacore/keda/issues/2498))

### Breaking Changes
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/metrics_api_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ func (s *metricsAPIScaler) getMetricValue(ctx context.Context) (*resource.Quanti
if err != nil {
return nil, err
}
defer r.Body.Close()

if r.StatusCode != http.StatusOK {
msg := fmt.Sprintf("api returned %d", r.StatusCode)
msg := fmt.Sprintf("%s: api returned %d", r.Request.URL.Path, r.StatusCode)
return nil, errors.New(msg)
}

defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
if err != nil {
return nil, err
Expand Down
30 changes: 30 additions & 0 deletions pkg/scalers/metrics_api_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package scalers
import (
"context"
"fmt"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/stretchr/testify/mock"
)

type metricsAPIMetadataTestData struct {
Expand Down Expand Up @@ -213,3 +216,30 @@ func TestBearerAuth(t *testing.T) {
t.Errorf("Error getting the metric")
}
}

type MockHTTPRoundTripper struct {
mock.Mock
}

func (m *MockHTTPRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) {
args := m.Called(request)
resp := args.Get(0).(*http.Response)
resp.Request = request
return resp, args.Error(1)
}

func TestGetMetricValueErrorMessage(t *testing.T) {
// mock roundtripper to return non-ok status code
mockHTTPRoundTripper := MockHTTPRoundTripper{}
mockHTTPRoundTripper.On("RoundTrip", mock.Anything).Return(&http.Response{StatusCode: http.StatusTeapot}, nil)

httpClient := http.Client{Transport: &mockHTTPRoundTripper}
s := metricsAPIScaler{
metadata: &metricsAPIScalerMetadata{url: "http://dummy:1230/api/v1/"},
client: &httpClient,
}

_, err := s.getMetricValue(context.TODO())

assert.Equal(t, err.Error(), "/api/v1/: api returned 418")
}

0 comments on commit cb53667

Please sign in to comment.