github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/utilization/azure_test.go (about) 1 package utilization 2 3 import ( 4 "net/http" 5 "testing" 6 7 "github.com/lulzWill/go-agent/internal/crossagent" 8 ) 9 10 func TestCrossAgentAzure(t *testing.T) { 11 var testCases []testCase 12 13 err := crossagent.ReadJSON("utilization_vendor_specific/azure.json", &testCases) 14 if err != nil { 15 t.Fatalf("reading azure.json failed: %v", err) 16 } 17 18 for _, testCase := range testCases { 19 client := &http.Client{ 20 Transport: &mockTransport{ 21 t: t, 22 responses: testCase.URIs, 23 }, 24 } 25 26 azure, err := getAzure(client) 27 28 if testCase.ExpectedVendorsHash.Azure == nil { 29 if err == nil { 30 t.Fatalf("%s: expected error; got nil", testCase.TestName) 31 } 32 } else { 33 if err != nil { 34 t.Fatalf("%s: expected no error; got %v", testCase.TestName, err) 35 } 36 37 if azure.Location != testCase.ExpectedVendorsHash.Azure.Location { 38 t.Fatalf("%s: Location incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.Azure.Location, azure.Location) 39 } 40 41 if azure.Name != testCase.ExpectedVendorsHash.Azure.Name { 42 t.Fatalf("%s: Name incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.Azure.Name, azure.Name) 43 } 44 45 if azure.VMID != testCase.ExpectedVendorsHash.Azure.VMID { 46 t.Fatalf("%s: VMID incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.Azure.VMID, azure.VMID) 47 } 48 49 if azure.VMSize != testCase.ExpectedVendorsHash.Azure.VMSize { 50 t.Fatalf("%s: VMSize incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.Azure.VMSize, azure.VMSize) 51 } 52 } 53 } 54 }