Example #1
0
func TestTypes(t *testing.T) {
	resp := fixtures.Types()
	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 Types")

	types, err := to.Types()
	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")
	}

	for _, n := range types {
		if n.Name != "EDGE" {
			testHelper.Error(t, "Should get back \"EDGE\" for \"Name\", got %s", n.Name)
		} else {
			testHelper.Success(t, "Should get back \"EDGE\" for \"Name\"")
		}

		if n.Description != "edge cache" {
			testHelper.Error(t, "Should get back \"edge cache\" for \"Description\", got %s", n.Description)
		} else {
			testHelper.Success(t, "Should get back \"edge cache\" for \"Description\"")
		}
	}
}
Example #2
0
func TestTypesUnauthorized(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 Types")

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