rimashah25 commented on a change in pull request #5960:
URL: https://github.com/apache/trafficcontrol/pull/5960#discussion_r677891452
##########
File path: traffic_ops/testing/api/v4/origins_test.go
##########
@@ -374,3 +473,411 @@ func DeleteTestOrigins(t *testing.T) {
}
}
}
+
+func GetTestOriginsByParams(t *testing.T) {
+ if len(testData.Origins) < 1 {
+ t.Fatal("Need at least one Origin to test Get Origins by
params")
+ }
+ origins := testData.Origins[0]
+ if origins.Name == nil || len(*origins.Name) == 0 {
+ t.Fatal("Found nil value in Origin name")
+ }
+ opts := client.NewRequestOptions()
+ opts.QueryParameters.Set("name", *origins.Name)
+ originByName, _, _ := TOSession.GetOrigins(opts)
+ if len(originByName.Response) < 1 {
+ t.Fatalf("Expected atleast one Origin for GET Origin by
Delivery Service, but found %d", len(originByName.Response))
+ }
+ if originByName.Response[0].DeliveryServiceID == nil {
+ t.Fatal("Found nil value in delivery service")
+ }
+ if originByName.Response[0].CachegroupID == nil {
+ t.Fatal("Found nil value in Cachegroup")
+ }
+ if originByName.Response[0].CoordinateID == nil {
+ t.Fatal("Found nil value in Coordinate")
+ }
+ if originByName.Response[0].ProfileID == nil {
+ t.Fatal("Found nil value in Profile")
+ }
+ if originByName.Response[0].IsPrimary == nil {
+ t.Fatal("Found nil value in IsPrimary field")
+ }
+
+ //Get Origins by DSID
+ dsId := *originByName.Response[0].DeliveryServiceID
+ opts.QueryParameters.Del("name")
+ opts.QueryParameters.Set("deliveryservice", strconv.Itoa(dsId))
+ originByDs, _, err := TOSession.GetOrigins(opts)
+ if err != nil {
+ t.Errorf("cannot get Origin by DeliveryService ID: %v - alerts:
%+v", err, originByDs.Alerts)
+ }
+ if len(originByDs.Response) < 1 {
+ t.Fatalf("Expected atleast one Origin for GET Origin by
Delivery Service, but found %d", len(originByDs.Response))
+ }
+
+ //Get Origins by Cachegroup
+ cachegroupID := *originByName.Response[0].CachegroupID
+ opts.QueryParameters.Del("deliveryservice")
+ opts.QueryParameters.Set("cachegroup", strconv.Itoa(cachegroupID))
+ originByCg, _, err := TOSession.GetOrigins(opts)
+ if err != nil {
+ t.Errorf("cannot get Origin by Cachegroup ID: %v - alerts:
%+v", err, originByCg.Alerts)
+ }
+ if len(originByCg.Response) < 1 {
+ t.Fatalf("Expected atleast one Origin for GET Origin by
Cachegroups, but found %d", len(originByCg.Response))
+ }
+
+ //Get Origins by Coordinate
+ CoordinateID := *originByName.Response[0].CoordinateID
+ opts.QueryParameters.Del("cachegroup")
+ opts.QueryParameters.Set("coordinate", strconv.Itoa(CoordinateID))
+ originByCoordinate, _, err := TOSession.GetOrigins(opts)
+ if err != nil {
+ t.Errorf("cannot get Origin by Coordinate ID: %v - alerts:
%+v", err, originByCoordinate.Alerts)
+ }
+ if len(originByCoordinate.Response) < 1 {
+ t.Fatalf("Expected atleast one Origin for GET Origin by
Coordinate, but found %d", len(originByCoordinate.Response))
+ }
+
+ //Get Origins by Profile
+ profileId := *originByName.Response[0].ProfileID
+ opts.QueryParameters.Del("coordinate")
+ opts.QueryParameters.Set("profileId", strconv.Itoa(profileId))
+ originByProfile, _, err := TOSession.GetOrigins(opts)
+ if err != nil {
+ t.Errorf("cannot get Origin by Profile ID: %v - alerts: %+v",
err, originByProfile.Alerts)
+ }
+ if len(originByProfile.Response) < 1 {
+ t.Fatalf("Expected atleast one Origin for GET Origin by
Profile, but found %d", len(originByProfile.Response))
+ }
+
+ //Get Origins by Primary
+ isPrimary := *originByName.Response[0].IsPrimary
+ opts.QueryParameters.Del("profileId")
+ opts.QueryParameters.Set("isPrimary", strconv.FormatBool(isPrimary))
+ originByPrimary, _, err := TOSession.GetOrigins(opts)
+ if err != nil {
+ t.Errorf("cannot get Origin by Primary ID: %v - alerts: %+v",
err, originByPrimary.Alerts)
+ }
+ if len(originByPrimary.Response) < 1 {
+ t.Fatalf("Expected atleast one Origin for GET Origin by
Primary, but found %d", len(originByPrimary.Response))
+ }
+
+ //Get Origins by Tenant
+ tenant := *originByName.Response[0].TenantID
+ opts.QueryParameters.Del("isPrimary")
+ opts.QueryParameters.Set("tenant", strconv.Itoa(tenant))
+ originByTenant, _, err := TOSession.GetOrigins(opts)
+ if err != nil {
+ t.Errorf("cannot get Origin by Tenant ID: %v - alerts: %+v",
err, originByTenant.Alerts)
+ }
+ if len(originByTenant.Response) < 1 {
+ t.Fatalf("Expected atleast one Origin for GET Origin by Tenant,
but found %d", len(originByTenant.Response))
+ }
+}
+
+func GetTestOriginsByInvalidParams(t *testing.T) {
Review comment:
Do we need to test negative cases for `name`, `primary` and `dsid`?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]