ocket8888 commented on a change in pull request #4374: Create API v2 tests
URL: https://github.com/apache/trafficcontrol/pull/4374#discussion_r375392169
 
 

 ##########
 File path: traffic_ops/testing/api/v2/withobjs_test.go
 ##########
 @@ -0,0 +1,111 @@
+/*
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+package v2
+
+import (
+       "testing"
+)
+
+// WithObjs creates the objs in order, runs f, and defers deleting the objs in 
the same order.
+//
+// Because deletion is deferred, using this ensures objects will be cleaned up 
if f panics or calls t.Fatal, as much as possible.
+//
+// Note that f itself may still create things which are not cleaned up 
properly, and likewise, the object creation and deletion tests themselves may 
fail.
+// All tests in the Traffic Ops API Testing framework use the same Traffic Ops 
instance, with persistent data. Because of this, when any test fails, all 
subsequent tests should be considered invalid, irrespective whether they pass 
or fail. Users are encouraged to use `go test -failfast`.
+func WithObjs(t *testing.T, objs []TCObj, f func()) {
+       for _, obj := range objs {
+               defer withFuncs[obj].Delete(t)
+               withFuncs[obj].Create(t)
+       }
+       f()
+}
+
+type TCObj int
+
+const (
+       CacheGroups TCObj = iota
+       CacheGroupsDeliveryServices
+       CacheGroupParameters
+       CDNs
+       CDNFederations
+       Coordinates
+       DeliveryServices
+       DeliveryServiceRequests
+       DeliveryServiceRequestComments
+       DeliveryServicesRequiredCapabilities
+       Divisions
+       FederationResolvers
+       FederationUsers
+       Origins
+       Parameters
+       PhysLocations
+       Profiles
+       ProfileParameters
+       Regions
+       Roles
+       ServerCapabilities
+       ServerChecks
+       ServerServerCapabilities
+       Servers
+       Statuses
+       StaticDNSEntries
+       SteeringTargets
+       Tenants
+       TOExtensions
+       Types
+       Users
+       UsersDeliveryServices
 
 Review comment:
   Pretty sure these are deprecated and won't be in TO API v2

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to