github.com/newrelic/go-agent@v3.26.0+incompatible/internal/utilization/aws_test.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package utilization
     5  
     6  import (
     7  	"net/http"
     8  	"testing"
     9  
    10  	"github.com/newrelic/go-agent/internal/crossagent"
    11  )
    12  
    13  func TestCrossAgentAWS(t *testing.T) {
    14  	var testCases []testCase
    15  
    16  	err := crossagent.ReadJSON("utilization_vendor_specific/aws.json", &testCases)
    17  	if err != nil {
    18  		t.Fatalf("reading aws.json failed: %v", err)
    19  	}
    20  
    21  	for _, testCase := range testCases {
    22  		client := &http.Client{
    23  			Transport: &mockTransport{
    24  				t:         t,
    25  				responses: testCase.URIs,
    26  			},
    27  		}
    28  
    29  		aws, err := getAWS(client)
    30  
    31  		if testCase.ExpectedVendorsHash.AWS == nil {
    32  			if err == nil {
    33  				t.Fatalf("%s: expected error; got nil", testCase.TestName)
    34  			}
    35  		} else {
    36  			if err != nil {
    37  				t.Fatalf("%s: expected no error; got %v", testCase.TestName, err)
    38  			}
    39  
    40  			if aws.InstanceID != testCase.ExpectedVendorsHash.AWS.InstanceID {
    41  				t.Fatalf("%s: instanceId incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.AWS.InstanceID, aws.InstanceID)
    42  			}
    43  
    44  			if aws.InstanceType != testCase.ExpectedVendorsHash.AWS.InstanceType {
    45  				t.Fatalf("%s: instanceType incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.AWS.InstanceType, aws.InstanceType)
    46  			}
    47  
    48  			if aws.AvailabilityZone != testCase.ExpectedVendorsHash.AWS.AvailabilityZone {
    49  				t.Fatalf("%s: availabilityZone incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.AWS.AvailabilityZone, aws.AvailabilityZone)
    50  			}
    51  		}
    52  	}
    53  }