rob05c commented on a change in pull request #3163: Fix Traffic Ops Tenancy and 
Activity Bugs, Fix TO API Test Framework to work with Tenancy
URL: https://github.com/apache/trafficcontrol/pull/3163#discussion_r244457995
 
 

 ##########
 File path: traffic_ops/testing/api/v14/user_test.go
 ##########
 @@ -61,11 +63,10 @@ func CreateTestUsers(t *testing.T) {
        for _, user := range testData.Users {
 
                resp, _, err := TOSession.CreateUser(&user)
-               log.Debugln("Response: ", resp.Alerts)
-
                if err != nil {
-                       t.Errorf("could not CREATE user: %v\n", err)
+                       t.Fatalf("could not CREATE user: %v\n", err)
 
 Review comment:
   >Really should only use Fatalf if we can't recover from the situation
   
   That's exactly what happens here, that's why I changed it. If an error is 
returned, the following line
   ```
   log.Debugln("Response: ", resp.Alerts)
   ```
   
   will panic. If an error is returned, the test can't keep going, which is 
exactly what `Fatalf` is for. Because of the panic, the test won't get cleaned 
up anyway, and subsequent tests will fail anyway. Using `Fatal` instead of 
`Error` avoids the panic stacktrace, and makes it easier to see what went wrong 
to fix it.
   
   We really need to fix the API Test framework to clean up tests even if they 
panic or `t.Fatalf`. I don't think it'll be hard, I think it's as simple as 
changing all our tests from e.g.
   ```
   func TestCacheGroups(t *testing.T) {
        CreateTestTypes(t)
        CreateTestCacheGroups(t)
        GetTestCacheGroups(t)
        CheckCacheGroupsAuthentication(t)
        UpdateTestCacheGroups(t)
        DeleteTestCacheGroups(t)
        DeleteTestTypes(t)
   }
   ```
   To
   ```
   func TestCacheGroups(t *testing.T) {
        defer DeleteTestTypes(t)
        CreateTestTypes(t)
        defer DeleteTestCacheGroups(t)
        CreateTestCacheGroups(t)
        GetTestCacheGroups(t)
        CheckCacheGroupsAuthentication(t)
        UpdateTestCacheGroups(t)
   }
   ```
   (similar to 
https://github.com/apache/trafficcontrol/blob/d083557e1a59cd4620b7652fd2821bf5d18d1ad3/traffic_ops/testing/api/v14/origins_test.go#L24
 but the `defer Delete`s need to come before their `Create`s).
   
   But that should probably be its own PR.

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


With regards,
Apache Git Services

Reply via email to