Example #1
0
func TestServerShortName(t *testing.T) {
	resp := fixtures.Servers()
	server := testHelper.ValidHTTPServer(resp)
	defer server.Close()

	var httpClient http.Client
	to := client.Session{
		URL:       server.URL,
		UserAgent: &httpClient,
	}

	pattern := "edge"
	testHelper.Context(t, "Given the need to test a successful Traffic Ops request for servers that match Short Name: \"%s\"", pattern)

	servers, err := to.ServersShortNameSearch(pattern)
	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 servers[0] != "edge-alb-01" {
		testHelper.Error(t, "Should get back \"edge-alb-01\", got: %s", servers[0])
	} else {
		testHelper.Success(t, "Should get back \"edge-alb-01\"")
	}

	if servers[1] != "edge-alb-02" {
		testHelper.Error(t, "Should get back \"edge-alb-02\", got: %s", servers[1])
	} else {
		testHelper.Success(t, "Should get back \"edge-alb-02\"")
	}
}
Example #2
0
func TestServerShortNameUnauthorized(t *testing.T) {
	server := testHelper.InvalidHTTPServer(http.StatusUnauthorized)
	defer server.Close()

	var httpClient http.Client
	to := client.Session{
		URL:       server.URL,
		UserAgent: &httpClient,
	}

	pattern := "edge"
	testHelper.Context(t, "Given the need to test a failed Traffic Ops request for servers that match Short Name: \"%s\"", pattern)

	_, err := to.ServersShortNameSearch(pattern)
	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")
	}
}