Feature/filestorage sharenetworks list (#124)
* sfs: Add list for share networks
* sfs: Add acceptance tests for share network List
* sfs: Add more fields for filtering List requests
* sfs: Add pagination for share network List
* sfs: Change pagination to use MarkerPage
* sfs: Add acceptance tests for share network pagination
diff --git a/acceptance/openstack/sharedfilesystems/v2/sharenetworks.go b/acceptance/openstack/sharedfilesystems/v2/sharenetworks.go
index 1f75e90..b0aefd8 100644
--- a/acceptance/openstack/sharedfilesystems/v2/sharenetworks.go
+++ b/acceptance/openstack/sharedfilesystems/v2/sharenetworks.go
@@ -55,6 +55,6 @@
t.Logf("IP version: %d", sharenetwork.IPVersion)
t.Logf("Name: %s", sharenetwork.Name)
t.Logf("Description: %s", sharenetwork.Description)
- t.Logf("Created at: %s", sharenetwork.CreatedAt)
- t.Logf("Updated at: %s", sharenetwork.UpdatedAt)
+ t.Logf("Created at: %v", sharenetwork.CreatedAt)
+ t.Logf("Updated at: %v", sharenetwork.UpdatedAt)
}
diff --git a/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go b/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go
index e654251..d7d712b 100644
--- a/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go
+++ b/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go
@@ -4,6 +4,8 @@
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks"
+ "github.com/gophercloud/gophercloud/pagination"
)
func TestShareNetworkCreateDestroy(t *testing.T) {
@@ -21,3 +23,106 @@
defer DeleteShareNetwork(t, client, shareNetwork)
}
+
+func TestShareNetworkListDetail(t *testing.T) {
+ client, err := clients.NewSharedFileSystemV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create a shared file system client: %v", err)
+ }
+
+ allPages, err := sharenetworks.ListDetail(client, sharenetworks.ListOpts{}).AllPages()
+ if err != nil {
+ t.Fatalf("Unable to retrieve share networks: %v", err)
+ }
+
+ allShareNetworks, err := sharenetworks.ExtractShareNetworks(allPages)
+ if err != nil {
+ t.Fatalf("Unable to extract share networks: %v", err)
+ }
+
+ for _, shareNetwork := range allShareNetworks {
+ PrintShareNetwork(t, &shareNetwork)
+ }
+}
+
+// The test creates 2 shared networks and verifies that only the one(s) with
+// a particular name are being listed
+func TestShareNetworkListFiltering(t *testing.T) {
+ client, err := clients.NewSharedFileSystemV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create a shared file system client: %v", err)
+ }
+
+ shareNetwork, err := CreateShareNetwork(t, client)
+ if err != nil {
+ t.Fatalf("Unable to create share network: %v", err)
+ }
+ defer DeleteShareNetwork(t, client, shareNetwork)
+
+ shareNetwork, err = CreateShareNetwork(t, client)
+ if err != nil {
+ t.Fatalf("Unable to create share network: %v", err)
+ }
+ defer DeleteShareNetwork(t, client, shareNetwork)
+
+ options := sharenetworks.ListOpts{
+ Name: shareNetwork.Name,
+ }
+
+ allPages, err := sharenetworks.ListDetail(client, options).AllPages()
+ if err != nil {
+ t.Fatalf("Unable to retrieve share networks: %v", err)
+ }
+
+ allShareNetworks, err := sharenetworks.ExtractShareNetworks(allPages)
+ if err != nil {
+ t.Fatalf("Unable to extract share networks: %v", err)
+ }
+
+ for _, listedShareNetwork := range allShareNetworks {
+ if listedShareNetwork.Name != shareNetwork.Name {
+ t.Fatalf("The name of the share network was expected to be %s", shareNetwork.Name)
+ }
+ PrintShareNetwork(t, &listedShareNetwork)
+ }
+}
+
+func TestShareNetworkListPagination(t *testing.T) {
+ client, err := clients.NewSharedFileSystemV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create a shared file system client: %v", err)
+ }
+
+ shareNetwork, err := CreateShareNetwork(t, client)
+ if err != nil {
+ t.Fatalf("Unable to create share network: %v", err)
+ }
+ defer DeleteShareNetwork(t, client, shareNetwork)
+
+ shareNetwork, err = CreateShareNetwork(t, client)
+ if err != nil {
+ t.Fatalf("Unable to create share network: %v", err)
+ }
+ defer DeleteShareNetwork(t, client, shareNetwork)
+
+ count := 0
+
+ err = sharenetworks.ListDetail(client, sharenetworks.ListOpts{Offset: 0, Limit: 1}).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ _, err := sharenetworks.ExtractShareNetworks(page)
+ if err != nil {
+ t.Fatalf("Failed to extract share networks: %v", err)
+ return false, err
+ }
+
+ return true, nil
+ })
+ if err != nil {
+ t.Fatalf("Unable to retrieve share networks: %v", err)
+ }
+
+ if count < 2 {
+ t.Fatal("Expected to get at least 2 pages")
+ }
+
+}