You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2019/03/28 16:31:13 UTC

[GitHub] [trafficcontrol] moltzaum opened a new issue #3447: TO Client: Alerts are not returned even when they exist?

moltzaum opened a new issue #3447: TO Client: Alerts are not returned even when they exist?
URL: https://github.com/apache/trafficcontrol/issues/3447
 
 
   I am writing an api test for a PR I submitted: #3445
   
   I have the following code:
   
   ```
   func TryToDeleteDivision(t *testing.T) {
       division := testData.Divisions[0]
       resp, _, err := TOSession.DeleteDivisionByName(division.Name)
   
       fmt.Printf("resp: %v\n", resp)
       fmt.Printf("err: %v\n", err)
   
       if err == nil {
           t.Errorf("should not be able to delete a division prematurely")
           return
       }
   
       if len(resp.Alerts) == 0 {
           t.Errorf("error occurred while deleting division, but no alerts exist")
           return
       }
   
       switch resp.Alerts[0].Text {
       case "Resource not found.":
           t.Errorf("division with name %v does not exist", division.Name)
       case "This division is currently used by regions.":
           // expected return message
       default:
           t.Errorf("unexpected alert occurred: %v", resp)
       }
   }
   ```
   
   Below is the result. You can see that the error clearly returns the alert message I'm looking for, but when an error occurs the client doesn't return the alerts. At first glance this is confusing. Is there a particular reason this is done? I believe there is a go convention that says a returned error implies the first value is nil, but I don't think that makes sense in this case.
   
   I can write this particular test differently, but maybe this makes sense to change?
   
   ```
   resp: {[]}
   err: 400 Bad Request[400] - Error requesting Traffic Ops https://localhost:6443/api/1.3/divisions/name/division1 {"alerts":[{"level":"error","text":"This division is currently used by regions."}]}
   --- FAIL: TestDivisions (4.38s)
   	divisions_test.go:47: error occurred while deleting division, but no alerts exist
   FAIL
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services