jehunte commented on a change in pull request #4518: URL: https://github.com/apache/trafficcontrol/pull/4518#discussion_r428702684
########## File path: traffic_ops/testing/api/v3/servicecategories_test.go ########## @@ -0,0 +1,137 @@ +package v3 + +/* + + 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. +*/ + +import ( + "testing" + "time" + + "github.com/apache/trafficcontrol/lib/go-tc" + toclient "github.com/apache/trafficcontrol/traffic_ops/client" +) + +func TestServiceCategories(t *testing.T) { + WithObjs(t, []TCObj{ServiceCategories, Tenants, Users}, func() { + UpdateTestServiceCategories(t) + GetTestServiceCategories(t) + ServiceCategoryTenancyTest(t) + }) +} + +func CreateTestServiceCategories(t *testing.T) { + // loop through service categories, assign FKs and create + for _, sc := range testData.ServiceCategories { + resp, _, err := TOSession.CreateServiceCategory(sc) + if err != nil { + t.Errorf("could not CREATE service category: %v", err) + } + t.Log("Response: ", resp.Alerts) + } +} + +func GetTestServiceCategories(t *testing.T) { + for _, sc := range testData.ServiceCategories { + resp, _, err := TOSession.GetServiceCategoryByName(sc.Name) + if err != nil { + t.Errorf("cannot GET Service Category by name: %v - %v", err, resp) + } + } +} + +func UpdateTestServiceCategories(t *testing.T) { + firstServiceCategory := testData.ServiceCategories[0] + // Retrieve the Service Category by service category so we can get the id for the Update + resp, _, err := TOSession.GetServiceCategoryByName(firstServiceCategory.Name) + if err != nil { + t.Errorf("cannot GET Service Category by service category: %v - %v", firstServiceCategory.Name, err) + } + if len(resp) > 0 { + remoteServiceCategory := resp[0] + expectedServiceCategory := "service-category-test" + remoteServiceCategory.Name = expectedServiceCategory + var alert tc.Alerts + alert, _, err = TOSession.UpdateServiceCategoryByID(remoteServiceCategory.ID, remoteServiceCategory) + if err != nil { + t.Errorf("cannot UPDATE Service Category by id: %v - %v", err, alert) + } + + // Retrieve the Service Category to check service category got updated + resp, _, err = TOSession.GetServiceCategoryByID(remoteServiceCategory.ID) + if err != nil { + t.Errorf("cannot GET Service Category by service category: %v - %v", firstServiceCategory.Name, err) + } + + respServiceCategory := resp[0] Review comment: Line 61 there is a check for this `if len(resp) > 0` ---------------------------------------------------------------- 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: [email protected]
