Skip to content

Commit

Permalink
Add logging of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
varunch77 committed Jan 27, 2025
1 parent 3914f78 commit ff409b4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/metric_value_benchmark/entity_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package metric_value_benchmark
import (
"encoding/json"
"fmt"
"log"
"net/http"
"time"

Expand Down Expand Up @@ -81,13 +82,15 @@ func (t *EntityMetricsTestRunner) validateTestCase(name string, testCase struct

req, err := common.BuildListEntitiesForMetricRequest(testCase.requestBody, region)
if err != nil {
log.Printf("Failed to build ListEntitiesForMetric request for test case '%s': %v", name, err)
return testResult
}

// send the request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Printf("Failed to send request for test case '%s': %v", name, err)
return testResult
}
defer resp.Body.Close()
Expand All @@ -104,17 +107,36 @@ func (t *EntityMetricsTestRunner) validateTestCase(name string, testCase struct
}

if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
log.Printf("Failed to decode response for test case '%s': %v", name, err)
return testResult
}

if len(response.Entities) == 0 {
log.Printf("Response contains no entities for test case '%s'", name)
return testResult
}

entity := response.Entities[0]
if entity.KeyAttributes.Type != testCase.expectedEntity.entityType ||
entity.KeyAttributes.ResourceType != testCase.expectedEntity.resourceType ||
entity.KeyAttributes.Identifier != testCase.expectedEntity.instanceId {

log.Printf("Entity mismatch for test case '%s':\n"+
"Expected:\n"+
" Type: %s\n"+
" ResourceType: %s\n"+
" InstanceId: %s\n"+
"Got:\n"+
" Type: %s\n"+
" ResourceType: %s\n"+
" InstanceId: %s",
name,
testCase.expectedEntity.entityType,
testCase.expectedEntity.resourceType,
testCase.expectedEntity.instanceId,
entity.KeyAttributes.Type,
entity.KeyAttributes.ResourceType,
entity.KeyAttributes.Identifier)
return testResult
}

Expand Down

0 comments on commit ff409b4

Please sign in to comment.