func TestDeliveryServiceState(t *testing.T) { resp := fixtures.DeliveryServiceState() server := testHelper.ValidHTTPServer(resp) defer server.Close() var httpClient http.Client to := client.Session{ URL: server.URL, UserAgent: &httpClient, } testHelper.Context(t, "Given the need to test a successful Traffic Ops request for a DeliveryServiceState") state, err := to.DeliveryServiceState("123") if err != nil { testHelper.Error(t, "Should be able to make a request to Traffic Ops") } else { testHelper.Success(t, "Should be able to make a request to Traffic Ops") } if state.Failover.Destination.Location != "someLocation" { testHelper.Error(t, "Should get back \"someLocation\" for \"Failover.Destination.Location\", got: %s", state.Failover.Destination.Location) } else { testHelper.Success(t, "Should get back \"someLocation\" for \"Failover.Destination.Location\"") } if state.Enabled != true { testHelper.Error(t, "Should get back \"true\" for \"Enabled\", got: %s", state.Enabled) } else { testHelper.Success(t, "Should get back \"true\" for \"Enabled\"") } }
func TestDeliveryServiceStateUnauthorized(t *testing.T) { server := testHelper.InvalidHTTPServer(http.StatusUnauthorized) defer server.Close() var httpClient http.Client to := client.Session{ URL: server.URL, UserAgent: &httpClient, } testHelper.Context(t, "Given the need to test a failed Traffic Ops request for a DeliveryServiceState") _, err := to.DeliveryServiceState("123") if err == nil { testHelper.Error(t, "Should not be able to make a request to Traffic Ops") } else { testHelper.Success(t, "Should not be able to make a request to Traffic Ops") } }