ocket8888 commented on code in PR #6817:
URL: https://github.com/apache/trafficcontrol/pull/6817#discussion_r870660393


##########
traffic_ops/testing/api/v4/statuses_test.go:
##########
@@ -142,13 +145,26 @@ func GetTestStatusesIMS(t *testing.T) {
 }
 
 func CreateTestStatuses(t *testing.T) {
+       response, _, err := TOSession.GetStatuses(client.NewRequestOptions())
+       if err != nil {
+               t.Errorf("could not get statuses: %v", err)
+       }
+       statusNameMap := make(map[string]bool, 0)
+       for _, r := range response.Response {
+               statusNameMap[r.Name] = true
+       }
+
        for _, status := range testData.Statuses {
-               resp, _, err := TOSession.CreateStatus(status, 
client.RequestOptions{})
-               if err != nil {
-                       t.Errorf("could not create Status: %v - alerts: %+v", 
err, resp.Alerts)
+               if status.Name != nil {
+                       if _, ok := statusNameMap[*status.Name]; !ok {
+                               resp, _, err := TOSession.CreateStatus(status, 
client.NewRequestOptions())
+                               t.Log("Response: ", resp)
+                               if err != nil {
+                                       t.Errorf("could not create Status: %v - 
alerts: %+v", err, resp.Alerts)
+                               }
+                       }

Review Comment:
   You wouldn't need to build this map and do these checks if you just remove 
standard statuses from the testing fixture data.



##########
traffic_ops/traffic_ops_golang/status/statuses.go:
##########
@@ -40,6 +40,14 @@ type TOStatus struct {
        tc.StatusNullable
 }
 
+var statusNameMap = map[tc.CacheStatus]bool{
+       tc.CacheStatusAdminDown: true,
+       tc.CacheStatusOnline:    true,
+       tc.CacheStatusOffline:   true,
+       tc.CacheStatusReported:  true,
+       tc.CacheStatusPreProd:   true,
+}
+

Review Comment:
   This map is not used



##########
lib/go-tc/statuses.go:
##########
@@ -70,3 +70,19 @@ type StatusNullable struct {
        LastUpdated *TimeNoMod `json:"lastUpdated" db:"last_updated"`
        Name        *string    `json:"name" db:"name"`
 }
+
+func IsReservedStatus(status string) bool {

Review Comment:
   This function could use a GoDoc.



-- 
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]

Reply via email to