Example #1
0
func TestListMembers(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleMemberListSuccessfully(t)

	pages := 0
	err := ListAssociateMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", MemberListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractMembers(page)
		if err != nil {
			return false, err
		}

		if len(actual) != 2 {
			t.Fatalf("Expected 2 members, got %d", len(actual))
		}
		th.CheckDeepEquals(t, MemberWeb, actual[0])
		th.CheckDeepEquals(t, MemberDb, actual[1])

		return true, nil
	})

	th.AssertNoErr(t, err)

	if pages != 1 {
		t.Errorf("Expected 1 page, saw %d", pages)
	}
}
Example #2
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandlePolicyListSuccessfully(t)

	pages := 0
	pager := List(client.ServiceClient(), "60b15dad-5ea1-43fa-9a12-a1d737b4da07")

	err := pager.EachPage(func(page pagination.Page) (bool, error) {
		pages++

		policies, err := ExtractPolicies(page)

		if err != nil {
			return false, err
		}

		if len(policies) != 3 {
			t.Fatalf("Expected 3 policies, got %d", len(policies))
		}

		th.CheckDeepEquals(t, WebhookPolicy, policies[0])
		th.CheckDeepEquals(t, OneTimePolicy, policies[1])
		th.CheckDeepEquals(t, SundayAfternoonPolicy, policies[2])

		return true, nil
	})

	th.AssertNoErr(t, err)

	if pages != 1 {
		t.Errorf("Expected 1 page, saw %d", pages)
	}
}
Example #3
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleWebhookListSuccessfully(t)

	pages := 0
	pager := List(client.ServiceClient(), groupID, policyID)

	err := pager.EachPage(func(page pagination.Page) (bool, error) {
		pages++

		webhooks, err := ExtractWebhooks(page)

		if err != nil {
			return false, err
		}

		if len(webhooks) != 2 {
			t.Fatalf("Expected 2 policies, got %d", len(webhooks))
		}

		th.CheckDeepEquals(t, FirstWebhook, webhooks[0])
		th.CheckDeepEquals(t, SecondWebhook, webhooks[1])

		return true, nil
	})

	th.AssertNoErr(t, err)

	if pages != 1 {
		t.Errorf("Expected 1 page, saw %d", pages)
	}
}
func TestListServers(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleServerListSuccessfully(t)

	pages := 0
	err := List(client.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractServers(page)
		if err != nil {
			return false, err
		}

		if len(actual) != 2 {
			t.Fatalf("Expected 2 servers, got %d", len(actual))
		}
		th.CheckDeepEquals(t, ServerHerp, actual[0])
		th.CheckDeepEquals(t, ServerDerp, actual[1])

		return true, nil
	})

	th.AssertNoErr(t, err)

	if pages != 1 {
		t.Errorf("Expected 1 page, saw %d", pages)
	}
}
Example #5
0
// GetIsSuccessful ensures that a GetResult was successful and contains the correct token and
// User Info.
func GetIsSuccessful(t *testing.T, result GetResult) {
	token, err := result.ExtractToken()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ExpectedToken, token)

	user, err := result.ExtractUser()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ExpectedUser, user)
}
Example #6
0
// IsSuccessful ensures that a CreateResult was successful and contains the correct token and
// service catalog.
func IsSuccessful(t *testing.T, result CreateResult) {
	token, err := result.ExtractToken()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ExpectedToken, token)

	serviceCatalog, err := result.ExtractServiceCatalog()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ExpectedServiceCatalog, serviceCatalog)
}
func TestMaybeString(t *testing.T) {
	testString := ""
	var expected *string
	actual := MaybeString(testString)
	th.CheckDeepEquals(t, expected, actual)

	testString = "carol"
	expected = &testString
	actual = MaybeString(testString)
	th.CheckDeepEquals(t, expected, actual)
}
func TestMaybeInt(t *testing.T) {
	testInt := 0
	var expected *int
	actual := MaybeInt(testInt)
	th.CheckDeepEquals(t, expected, actual)

	testInt = 4
	expected = &testInt
	actual = MaybeInt(testInt)
	th.CheckDeepEquals(t, expected, actual)
}
func TestApplyDefaultsToEndpointOpts(t *testing.T) {
	eo := EndpointOpts{Availability: AvailabilityPublic}
	eo.ApplyDefaults("compute")
	expected := EndpointOpts{Availability: AvailabilityPublic, Type: "compute"}
	th.CheckDeepEquals(t, expected, eo)

	eo = EndpointOpts{Type: "compute"}
	eo.ApplyDefaults("object-store")
	expected = EndpointOpts{Availability: AvailabilityPublic, Type: "compute"}
	th.CheckDeepEquals(t, expected, eo)
}
Example #10
0
func TestListAllServers(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleServerListSuccessfully(t)

	allPages, err := List(client.ServiceClient(), ListOpts{}).AllPages()
	th.AssertNoErr(t, err)
	actual, err := ExtractServers(allPages)
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ServerHerp, actual[0])
	th.CheckDeepEquals(t, ServerDerp, actual[1])
}
Example #11
0
func TestListAllMembers(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleMemberListSuccessfully(t)

	allPages, err := ListAssociateMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", MemberListOpts{}).AllPages()
	th.AssertNoErr(t, err)
	actual, err := ExtractMembers(allPages)
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, MemberWeb, actual[0])
	th.CheckDeepEquals(t, MemberDb, actual[1])
}
Example #12
0
func TestListAllHealthmonitors(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleHealthmonitorListSuccessfully(t)

	allPages, err := List(fake.ServiceClient(), ListOpts{}).AllPages()
	th.AssertNoErr(t, err)
	actual, err := ExtractMonitors(allPages)
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, HealthmonitorWeb, actual[0])
	th.CheckDeepEquals(t, HealthmonitorDb, actual[1])
}
Example #13
0
func TestMeterStatistics(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleMeterStatisticsSuccessfully(t)

	list, err := MeterStatistics(client.ServiceClient(), "memory", MeterStatisticsOpts{}).Extract()
	th.AssertNoErr(t, err)

	if len(list) != 2 {
		t.Fatalf("Expected 2 statistics, got %d", len(list))
	}
	th.CheckDeepEquals(t, StatisticsHerp, (list)[0])
	th.CheckDeepEquals(t, StatisticsDerp, (list)[1])
}
Example #14
0
func TestListMeters(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleMeterListSuccessfully(t)

	list, err := List(client.ServiceClient(), ListOpts{}).Extract()
	th.AssertNoErr(t, err)

	if len(list) != 2 {
		t.Fatalf("Expected 2 meters, got %d", len(list))
	}
	th.CheckDeepEquals(t, MeterHerp, (list)[0])
	th.CheckDeepEquals(t, MeterDerp, (list)[1])
}
Example #15
0
func TestRole(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockListRoleResponse(t)

	count := 0

	err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := os.ExtractRoles(page)
		if err != nil {
			t.Errorf("Failed to extract users: %v", err)
			return false, err
		}

		expected := []os.Role{
			os.Role{
				ID:          "123",
				Name:        "compute:admin",
				Description: "Nova Administrator",
				ServiceID:   "cke5372ebabeeabb70a0e702a4626977x4406e5",
			},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, count)
}
Example #16
0
func TestListByServer(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockListGroupsByServerResponse(t, serverID)

	count := 0

	err := ListByServer(client.ServiceClient(), serverID).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractSecurityGroups(page)
		if err != nil {
			t.Errorf("Failed to extract users: %v", err)
			return false, err
		}

		expected := []SecurityGroup{
			SecurityGroup{
				ID:          groupID,
				Description: "default",
				Name:        "default",
				Rules:       []Rule{},
				TenantID:    "openstack",
			},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, count)
}
Example #17
0
func TestEnumerateMarker(t *testing.T) {
	pager := createMarkerPaged(t)
	defer testhelper.TeardownHTTP()

	callCount := 0
	err := pager.EachPage(func(page Page) (bool, error) {
		actual, err := ExtractMarkerStrings(page)
		if err != nil {
			return false, err
		}

		t.Logf("Handler invoked with %v", actual)

		var expected []string
		switch callCount {
		case 0:
			expected = []string{"aaa", "bbb", "ccc"}
		case 1:
			expected = []string{"ddd", "eee", "fff"}
		case 2:
			expected = []string{"ggg", "hhh", "iii"}
		default:
			t.Fatalf("Unexpected call count: %d", callCount)
			return false, nil
		}

		testhelper.CheckDeepEquals(t, expected, actual)

		callCount++
		return true, nil
	})
	testhelper.AssertNoErr(t, err)
	testhelper.AssertEquals(t, callCount, 3)
}
Example #18
0
func TestListImageDetails(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	th.Mux.HandleFunc("/images/detail", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		w.Header().Add("Content-Type", "application/json")
		r.ParseForm()
		marker := r.Form.Get("marker")
		switch marker {
		case "":
			fmt.Fprintf(w, ListOutput)
		case "e19a734c-c7e6-443a-830c-242209c4d65d":
			fmt.Fprintf(w, `{ "images": [] }`)
		default:
			t.Fatalf("Unexpected marker: [%s]", marker)
		}
	})

	count := 0
	err := ListDetail(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractImages(page)
		th.AssertNoErr(t, err)
		th.CheckDeepEquals(t, ExpectedImageSlice, actual)

		return true, nil
	})
	th.AssertNoErr(t, err)
	th.CheckEquals(t, 1, count)
}
Example #19
0
func TestListProtocols(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockListProtocolsResponse(t)

	count := 0

	err := ListProtocols(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractProtocols(page)
		th.AssertNoErr(t, err)

		expected := []Protocol{
			Protocol{Name: "DNS_TCP", Port: 53},
			Protocol{Name: "DNS_UDP", Port: 53},
			Protocol{Name: "FTP", Port: 21},
			Protocol{Name: "HTTP", Port: 80},
			Protocol{Name: "HTTPS", Port: 443},
			Protocol{Name: "IMAPS", Port: 993},
			Protocol{Name: "IMAPv4", Port: 143},
		}

		th.CheckDeepEquals(t, expected[0:7], actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, count)
}
Example #20
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleList(t)

	expectedDBs := []Database{
		Database{Name: "anotherexampledb"},
		Database{Name: "exampledb"},
		Database{Name: "nextround"},
		Database{Name: "sampledb"},
		Database{Name: "testingdb"},
	}

	pages := 0
	err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractDBs(page)
		if err != nil {
			return false, err
		}

		th.CheckDeepEquals(t, expectedDBs, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)

	if pages != 1 {
		t.Errorf("Expected 1 page, saw %d", pages)
	}
}
Example #21
0
func TestListCerts(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockListCertsResponse(t, lbID)

	count := 0

	err := ListCerts(client.ServiceClient(), lbID).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractCerts(page)
		th.AssertNoErr(t, err)

		expected := []Certificate{
			Certificate{ID: 123, HostName: "rackspace.com"},
			Certificate{ID: 124, HostName: "*.rackspace.com"},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, count)
}
Example #22
0
func TestInstanceList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	fixture.SetupHandler(t, "/instances", "GET", "", listInstancesResp, 200)

	opts := &ListOpts{
		IncludeHA:       false,
		IncludeReplicas: false,
	}

	pages := 0
	err := List(fake.ServiceClient(), opts).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractInstances(page)
		if err != nil {
			return false, err
		}

		th.CheckDeepEquals(t, []Instance{*expectedInstance}, actual)
		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
Example #23
0
func TestListingUserRoles(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockListRolesResponse(t)

	tenantID := "1d8b6120dcc640fda4fc9194ffc80273"
	userID := "c39e3de9be2d4c779f1dfd6abacc176d"

	err := ListRoles(client.ServiceClient(), tenantID, userID).EachPage(func(page pagination.Page) (bool, error) {
		actual, err := ExtractRoles(page)
		th.AssertNoErr(t, err)

		expected := []Role{
			Role{ID: "9fe2ff9ee4384b1894a90878d3e92bab", Name: "foo_role"},
			Role{ID: "1ea3d56793574b668e85960fbf651e13", Name: "admin"},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
}
Example #24
0
func TestListAlgorithms(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockListAlgorithmsResponse(t)

	count := 0

	err := ListAlgorithms(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractAlgorithms(page)
		th.AssertNoErr(t, err)

		expected := []Algorithm{
			Algorithm{Name: "LEAST_CONNECTIONS"},
			Algorithm{Name: "RANDOM"},
			Algorithm{Name: "ROUND_ROBIN"},
			Algorithm{Name: "WEIGHTED_LEAST_CONNECTIONS"},
			Algorithm{Name: "WEIGHTED_ROUND_ROBIN"},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, count)
}
Example #25
0
func TestGetHomeDocument(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	os.HandleGetSuccessfully(t)

	actual, err := Get(fake.ServiceClient()).Extract()
	th.CheckNoErr(t, err)

	expected := os.HomeDocument{
		"rel/cdn": map[string]interface{}{
			"href-template": "services{?marker,limit}",
			"href-vars": map[string]interface{}{
				"marker": "param/marker",
				"limit":  "param/limit",
			},
			"hints": map[string]interface{}{
				"allow": []string{"GET"},
				"formats": map[string]interface{}{
					"application/json": map[string]interface{}{},
				},
			},
		},
	}
	th.CheckDeepEquals(t, expected, *actual)
}
Example #26
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockListRulesResponse(t)

	count := 0

	err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractDefaultRules(page)
		th.AssertNoErr(t, err)

		expected := []DefaultRule{
			DefaultRule{
				FromPort:   80,
				ID:         ruleID,
				IPProtocol: "TCP",
				IPRange:    secgroups.IPRange{CIDR: "10.10.10.0/24"},
				ToPort:     80,
			},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, count)
}
Example #27
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockListResponse(t, lbID)

	count := 0

	err := List(client.ServiceClient(), lbID).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractAccessList(page)
		th.AssertNoErr(t, err)

		expected := AccessList{
			NetworkItem{Address: "206.160.163.21", ID: 21, Type: DENY},
			NetworkItem{Address: "206.160.163.22", ID: 22, Type: DENY},
			NetworkItem{Address: "206.160.163.23", ID: 23, Type: DENY},
			NetworkItem{Address: "206.160.163.24", ID: 24, Type: DENY},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, count)
}
Example #28
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockListResponse(t, lbID)

	count := 0

	err := List(client.ServiceClient(), lbID).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractVIPs(page)
		th.AssertNoErr(t, err)

		expected := []VIP{
			VIP{ID: 1000, Address: "206.10.10.210", Type: "PUBLIC"},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, count)
}
Example #29
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	os.MockListResponse(t)

	count := 0

	err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractVolumes(page)
		if err != nil {
			t.Errorf("Failed to extract volumes: %v", err)
			return false, err
		}

		expected := []Volume{
			Volume{
				ID:   "289da7f8-6440-407c-9fb4-7db01ec49164",
				Name: "vol-001",
			},
			Volume{
				ID:   "96c3bda7-c82a-4f50-be73-ca7621794835",
				Name: "vol-002",
			},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertEquals(t, 1, count)
	th.AssertNoErr(t, err)
}
Example #30
0
func TestListAll(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockListResponse(t)

	allPages, err := List(client.ServiceClient(), &ListOpts{}).AllPages()
	th.AssertNoErr(t, err)
	actual, err := ExtractVolumes(allPages)
	th.AssertNoErr(t, err)

	expected := []Volume{
		Volume{
			ID:   "289da7f8-6440-407c-9fb4-7db01ec49164",
			Name: "vol-001",
		},
		Volume{
			ID:   "96c3bda7-c82a-4f50-be73-ca7621794835",
			Name: "vol-002",
		},
	}

	th.CheckDeepEquals(t, expected, actual)

}