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

	allPages, err := servers.ListAddresses(client.ServiceClient(), "asdfasdfasdf").AllPages()
	th.AssertNoErr(t, err)
	_, err = servers.ExtractAddresses(allPages)
	th.AssertNoErr(t, err)
}
Example #2
0
func TestServersCreateDestroy(t *testing.T) {
	client, err := clients.NewComputeV2Client()
	if err != nil {
		t.Fatalf("Unable to create a compute client: %v", err)
	}

	choices, err := clients.AcceptanceTestChoicesFromEnv()
	if err != nil {
		t.Fatal(err)
	}

	server, err := CreateServer(t, client, choices)
	if err != nil {
		t.Fatalf("Unable to create server: %v", err)
	}

	defer DeleteServer(t, client, server)

	newServer, err := servers.Get(client, server.ID).Extract()
	if err != nil {
		t.Errorf("Unable to retrieve server: %v", err)
	}
	PrintServer(t, newServer)

	allAddressPages, err := servers.ListAddresses(client, server.ID).AllPages()
	if err != nil {
		t.Errorf("Unable to list server addresses: %v", err)
	}

	allAddresses, err := servers.ExtractAddresses(allAddressPages)
	if err != nil {
		t.Errorf("Unable to extract server addresses: %v", err)
	}

	for network, address := range allAddresses {
		t.Logf("Addresses on %s: %+v", network, address)
	}

	allNetworkAddressPages, err := servers.ListAddressesByNetwork(client, server.ID, choices.NetworkName).AllPages()
	if err != nil {
		t.Errorf("Unable to list server addresses: %v", err)
	}

	allNetworkAddresses, err := servers.ExtractNetworkAddresses(allNetworkAddressPages)
	if err != nil {
		t.Errorf("Unable to extract server addresses: %v", err)
	}

	t.Logf("Addresses on %s:", choices.NetworkName)
	for _, address := range allNetworkAddresses {
		t.Logf("%+v", address)
	}
}
Example #3
0
func TestListAddresses(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleAddressListSuccessfully(t)

	expected := ListAddressesExpected
	pages := 0
	err := servers.ListAddresses(client.ServiceClient(), "asdfasdfasdf").EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := servers.ExtractAddresses(page)
		th.AssertNoErr(t, err)

		if len(actual) != 2 {
			t.Fatalf("Expected 2 networks, got %d", len(actual))
		}
		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})
	th.AssertNoErr(t, err)
	th.CheckEquals(t, 1, pages)
}