rawlinp commented on a change in pull request #4030: Rewrite PUT 
/api/1.1/servers/:id/status to Go
URL: https://github.com/apache/trafficcontrol/pull/4030#discussion_r340286906
 
 

 ##########
 File path: traffic_ops/testing/api/v14/serverupdatestatus_test.go
 ##########
 @@ -0,0 +1,149 @@
+package v14
+
+/*
+
+   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"
+
+       "github.com/apache/trafficcontrol/lib/go-tc"
+       "github.com/apache/trafficcontrol/lib/go-util"
+)
+
+func TestServerUpdateStatus(t *testing.T) {
+       WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles, Statuses, 
Divisions, Regions, PhysLocations, CacheGroups, Servers}, func() {
+               UpdateTestServerStatus(t)
+       })
+}
+
+func UpdateTestServerStatus(t *testing.T) {
+
+       edge1cdn1 := tc.Server{}
+       edge2cdn1 := tc.Server{}
+       mid1cdn1 := tc.Server{}
+       edge1cdn2 := tc.Server{}
+
+       getServers := func() {
+               for _, s := range []struct {
+                       name   string
+                       server *tc.Server
+               }{
+                       {
+                               "atlanta-edge-01",
+                               &edge1cdn1,
+                       },
+                       {
+                               "atlanta-edge-03",
+                               &edge2cdn1,
+                       },
+                       {
+                               "atlanta-mid-16",
+                               &mid1cdn1,
+                       },
+                       {
+                               "edge1-cdn2",
+                               &edge1cdn2,
+                       },
+               } {
+                       resp, _, err := TOSession.GetServerByHostName(s.name)
+                       if err != nil {
+                               t.Errorf("cannot GET Server by hostname: %v - 
%v\n", s.name, err)
+                       }
+                       *s.server = resp[0]
+               }
+       }
+       getServers()
+
+       // assert that servers don't have updates pending
+       for _, s := range []tc.Server{
+               edge1cdn1,
+               edge2cdn1,
+               mid1cdn1,
+               edge1cdn2,
+       } {
+               if s.UpdPending {
+                       t.Errorf("expected UpdPending: false, actual: true")
+               }
+       }
+
+       // update status of MID server to OFFLINE
+       _, _, err := TOSession.UpdateServerStatus(mid1cdn1.ID, 
tc.ServerPutStatus{
+               Status:        util.JSONNameOrIDStr{Name: 
util.StrPtr("OFFLINE")},
+               OfflineReason: util.StrPtr("testing")})
+       if err != nil {
+               t.Errorf("cannot update server status: %v", err)
+       }
+
+       // assert that updates were queued for the proper EDGE servers
+       getServers()
+       if !edge1cdn1.UpdPending {
+               t.Errorf("expected: child %s to have updates pending, actual: 
no updates pending", edge1cdn1.HostName)
+       }
+       if !edge2cdn1.UpdPending {
+               t.Errorf("expected: child %s to have updates pending, actual: 
no updates pending", edge2cdn1.HostName)
+       }
+       if mid1cdn1.UpdPending {
+               t.Errorf("expected: server %s with updated status to have no 
updates pending, actual: updates pending", mid1cdn1.HostName)
+       }
+       if edge1cdn2.UpdPending {
+               t.Errorf("expected: server %s in different CDN than server with 
updated status to have no updates pending, actual: updates pending", 
edge2cdn1.HostName)
+       }
+
+       // update status of MID server to OFFLINE via ID
+       status, _, err := TOSession.GetStatusByName("OFFLINE")
+       if err != nil {
+               t.Errorf("cannot GET status by name: %v", err)
 
 Review comment:
   done

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