github.com/newrelic/go-agent@v3.26.0+incompatible/internal/utilization/azure_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 TestCrossAgentAzure(t *testing.T) { 14 var testCases []testCase 15 16 err := crossagent.ReadJSON("utilization_vendor_specific/azure.json", &testCases) 17 if err != nil { 18 t.Fatalf("reading azure.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 azure, err := getAzure(client) 30 31 if testCase.ExpectedVendorsHash.Azure == 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 azure.Location != testCase.ExpectedVendorsHash.Azure.Location { 41 t.Fatalf("%s: Location incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.Azure.Location, azure.Location) 42 } 43 44 if azure.Name != testCase.ExpectedVendorsHash.Azure.Name { 45 t.Fatalf("%s: Name incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.Azure.Name, azure.Name) 46 } 47 48 if azure.VMID != testCase.ExpectedVendorsHash.Azure.VMID { 49 t.Fatalf("%s: VMID incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.Azure.VMID, azure.VMID) 50 } 51 52 if azure.VMSize != testCase.ExpectedVendorsHash.Azure.VMSize { 53 t.Fatalf("%s: VMSize incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.Azure.VMSize, azure.VMSize) 54 } 55 } 56 } 57 }