github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go (about)

     1  //go:build acceptance
     2  // +build acceptance
     3  
     4  package v2
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/gophercloud/gophercloud/internal/acceptance/clients"
    10  	"github.com/gophercloud/gophercloud/internal/acceptance/tools"
    11  	"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices"
    12  )
    13  
    14  func TestSecurityServiceCreateDelete(t *testing.T) {
    15  	client, err := clients.NewSharedFileSystemV2Client()
    16  	if err != nil {
    17  		t.Fatalf("Unable to create shared file system client: %v", err)
    18  	}
    19  
    20  	securityService, err := CreateSecurityService(t, client)
    21  	if err != nil {
    22  		t.Fatalf("Unable to create security service: %v", err)
    23  	}
    24  
    25  	newSecurityService, err := securityservices.Get(client, securityService.ID).Extract()
    26  	if err != nil {
    27  		t.Errorf("Unable to retrieve the security service: %v", err)
    28  	}
    29  
    30  	if newSecurityService.Name != securityService.Name {
    31  		t.Fatalf("Security service name was expeted to be: %s", securityService.Name)
    32  	}
    33  
    34  	if newSecurityService.Description != securityService.Description {
    35  		t.Fatalf("Security service description was expeted to be: %s", securityService.Description)
    36  	}
    37  
    38  	tools.PrintResource(t, securityService)
    39  
    40  	defer DeleteSecurityService(t, client, securityService)
    41  }
    42  
    43  func TestSecurityServiceList(t *testing.T) {
    44  	client, err := clients.NewSharedFileSystemV2Client()
    45  	if err != nil {
    46  		t.Fatalf("Unable to create a shared file system client: %v", err)
    47  	}
    48  
    49  	allPages, err := securityservices.List(client, securityservices.ListOpts{}).AllPages()
    50  	if err != nil {
    51  		t.Fatalf("Unable to retrieve security services: %v", err)
    52  	}
    53  
    54  	allSecurityServices, err := securityservices.ExtractSecurityServices(allPages)
    55  	if err != nil {
    56  		t.Fatalf("Unable to extract security services: %v", err)
    57  	}
    58  
    59  	for _, securityService := range allSecurityServices {
    60  		tools.PrintResource(t, &securityService)
    61  	}
    62  }
    63  
    64  // The test creates 2 security services and verifies that only the one(s) with
    65  // a particular name are being listed
    66  func TestSecurityServiceListFiltering(t *testing.T) {
    67  	client, err := clients.NewSharedFileSystemV2Client()
    68  	if err != nil {
    69  		t.Fatalf("Unable to create a shared file system client: %v", err)
    70  	}
    71  
    72  	securityService, err := CreateSecurityService(t, client)
    73  	if err != nil {
    74  		t.Fatalf("Unable to create security service: %v", err)
    75  	}
    76  	defer DeleteSecurityService(t, client, securityService)
    77  
    78  	securityService, err = CreateSecurityService(t, client)
    79  	if err != nil {
    80  		t.Fatalf("Unable to create security service: %v", err)
    81  	}
    82  	defer DeleteSecurityService(t, client, securityService)
    83  
    84  	options := securityservices.ListOpts{
    85  		Name: securityService.Name,
    86  	}
    87  
    88  	allPages, err := securityservices.List(client, options).AllPages()
    89  	if err != nil {
    90  		t.Fatalf("Unable to retrieve security services: %v", err)
    91  	}
    92  
    93  	allSecurityServices, err := securityservices.ExtractSecurityServices(allPages)
    94  	if err != nil {
    95  		t.Fatalf("Unable to extract security services: %v", err)
    96  	}
    97  
    98  	for _, listedSecurityService := range allSecurityServices {
    99  		if listedSecurityService.Name != securityService.Name {
   100  			t.Fatalf("The name of the security service was expected to be %s", securityService.Name)
   101  		}
   102  		tools.PrintResource(t, &listedSecurityService)
   103  	}
   104  }
   105  
   106  // Create a security service and update the name and description. Get the security
   107  // service and verify that the name and description have been updated
   108  func TestSecurityServiceUpdate(t *testing.T) {
   109  	client, err := clients.NewSharedFileSystemV2Client()
   110  	if err != nil {
   111  		t.Fatalf("Unable to create shared file system client: %v", err)
   112  	}
   113  
   114  	securityService, err := CreateSecurityService(t, client)
   115  	if err != nil {
   116  		t.Fatalf("Unable to create security service: %v", err)
   117  	}
   118  
   119  	name := "NewName"
   120  	description := ""
   121  	options := securityservices.UpdateOpts{
   122  		Name:        &name,
   123  		Description: &description,
   124  		Type:        "ldap",
   125  	}
   126  
   127  	_, err = securityservices.Update(client, securityService.ID, options).Extract()
   128  	if err != nil {
   129  		t.Errorf("Unable to update the security service: %v", err)
   130  	}
   131  
   132  	newSecurityService, err := securityservices.Get(client, securityService.ID).Extract()
   133  	if err != nil {
   134  		t.Errorf("Unable to retrieve the security service: %v", err)
   135  	}
   136  
   137  	if newSecurityService.Name != name {
   138  		t.Fatalf("Security service name was expeted to be: %s", name)
   139  	}
   140  
   141  	if newSecurityService.Description != description {
   142  		t.Fatalf("Security service description was expeted to be: %s", description)
   143  	}
   144  
   145  	if newSecurityService.Type != options.Type {
   146  		t.Fatalf("Security service type was expected to be: %s", options.Type)
   147  	}
   148  
   149  	tools.PrintResource(t, securityService)
   150  
   151  	defer DeleteSecurityService(t, client, securityService)
   152  }