github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/utilization/aws_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 TestCrossAgentAWS(t *testing.T) { 11 var testCases []testCase 12 13 err := crossagent.ReadJSON("utilization_vendor_specific/aws.json", &testCases) 14 if err != nil { 15 t.Fatalf("reading aws.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 aws, err := getAWS(client) 27 28 if testCase.ExpectedVendorsHash.AWS == 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 aws.InstanceID != testCase.ExpectedVendorsHash.AWS.InstanceID { 38 t.Fatalf("%s: instanceId incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.AWS.InstanceID, aws.InstanceID) 39 } 40 41 if aws.InstanceType != testCase.ExpectedVendorsHash.AWS.InstanceType { 42 t.Fatalf("%s: instanceType incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.AWS.InstanceType, aws.InstanceType) 43 } 44 45 if aws.AvailabilityZone != testCase.ExpectedVendorsHash.AWS.AvailabilityZone { 46 t.Fatalf("%s: availabilityZone incorrect; expected: %s; got: %s", testCase.TestName, testCase.ExpectedVendorsHash.AWS.AvailabilityZone, aws.AvailabilityZone) 47 } 48 } 49 } 50 }