github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/vnpaycloud-console/gophercloud/v2"
     9  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/sharedfilesystems/v2/securityservices"
    10  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    11  	"github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    12  )
    13  
    14  // Verifies that a security service can be created correctly
    15  func TestCreate(t *testing.T) {
    16  	th.SetupHTTP()
    17  	defer th.TeardownHTTP()
    18  
    19  	MockCreateResponse(t)
    20  
    21  	options := &securityservices.CreateOpts{
    22  		Name:        "SecServ1",
    23  		Description: "Creating my first Security Service",
    24  		DNSIP:       "10.0.0.0/24",
    25  		User:        "demo",
    26  		Password:    "***",
    27  		Type:        "kerberos",
    28  	}
    29  
    30  	s, err := securityservices.Create(context.TODO(), client.ServiceClient(), options).Extract()
    31  	th.AssertNoErr(t, err)
    32  
    33  	th.AssertEquals(t, s.Name, "SecServ1")
    34  	th.AssertEquals(t, s.Description, "Creating my first Security Service")
    35  	th.AssertEquals(t, s.User, "demo")
    36  	th.AssertEquals(t, s.DNSIP, "10.0.0.0/24")
    37  	th.AssertEquals(t, s.Password, "supersecret")
    38  	th.AssertEquals(t, s.Type, "kerberos")
    39  }
    40  
    41  // Verifies that a security service cannot be created without a type
    42  func TestCreateFails(t *testing.T) {
    43  	options := &securityservices.CreateOpts{
    44  		Name:        "SecServ1",
    45  		Description: "Creating my first Security Service",
    46  		DNSIP:       "10.0.0.0/24",
    47  		User:        "demo",
    48  		Password:    "***",
    49  	}
    50  
    51  	_, err := securityservices.Create(context.TODO(), client.ServiceClient(), options).Extract()
    52  	if _, ok := err.(gophercloud.ErrMissingInput); !ok {
    53  		t.Fatal("ErrMissingInput was expected to occur")
    54  	}
    55  }
    56  
    57  // Verifies that security service deletion works
    58  func TestDelete(t *testing.T) {
    59  	th.SetupHTTP()
    60  	defer th.TeardownHTTP()
    61  
    62  	MockDeleteResponse(t)
    63  
    64  	res := securityservices.Delete(context.TODO(), client.ServiceClient(), "securityServiceID")
    65  	th.AssertNoErr(t, res.Err)
    66  }
    67  
    68  // Verifies that security services can be listed correctly
    69  func TestList(t *testing.T) {
    70  	th.SetupHTTP()
    71  	defer th.TeardownHTTP()
    72  
    73  	MockListResponse(t)
    74  
    75  	allPages, err := securityservices.List(client.ServiceClient(), &securityservices.ListOpts{}).AllPages(context.TODO())
    76  	th.AssertNoErr(t, err)
    77  	actual, err := securityservices.ExtractSecurityServices(allPages)
    78  	th.AssertNoErr(t, err)
    79  	var nilTime time.Time
    80  	expected := []securityservices.SecurityService{
    81  		{
    82  			Status:      "new",
    83  			Domain:      "",
    84  			ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
    85  			Name:        "SecServ1",
    86  			CreatedAt:   time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC),
    87  			Description: "Creating my first Security Service",
    88  			UpdatedAt:   nilTime,
    89  			Server:      "",
    90  			DNSIP:       "10.0.0.0/24",
    91  			User:        "demo",
    92  			Password:    "supersecret",
    93  			Type:        "kerberos",
    94  			ID:          "3c829734-0679-4c17-9637-801da48c0d5f",
    95  		},
    96  		{
    97  			Status:      "new",
    98  			Domain:      "",
    99  			ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
   100  			Name:        "SecServ2",
   101  			CreatedAt:   time.Date(2015, 9, 7, 12, 25, 03, 0, time.UTC),
   102  			Description: "Creating my second Security Service",
   103  			UpdatedAt:   nilTime,
   104  			Server:      "",
   105  			DNSIP:       "10.0.0.0/24",
   106  			User:        "",
   107  			Password:    "",
   108  			Type:        "ldap",
   109  			ID:          "5a1d3a12-34a7-4087-8983-50e9ed03509a",
   110  		},
   111  	}
   112  
   113  	th.CheckDeepEquals(t, expected, actual)
   114  }
   115  
   116  // Verifies that security services list can be called with query parameters
   117  func TestFilteredList(t *testing.T) {
   118  	th.SetupHTTP()
   119  	defer th.TeardownHTTP()
   120  
   121  	MockFilteredListResponse(t)
   122  
   123  	options := &securityservices.ListOpts{
   124  		Type: "kerberos",
   125  	}
   126  
   127  	allPages, err := securityservices.List(client.ServiceClient(), options).AllPages(context.TODO())
   128  	th.AssertNoErr(t, err)
   129  	actual, err := securityservices.ExtractSecurityServices(allPages)
   130  	th.AssertNoErr(t, err)
   131  	var nilTime time.Time
   132  	expected := []securityservices.SecurityService{
   133  		{
   134  			Status:      "new",
   135  			Domain:      "",
   136  			ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
   137  			Name:        "SecServ1",
   138  			CreatedAt:   time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC),
   139  			Description: "Creating my first Security Service",
   140  			UpdatedAt:   nilTime,
   141  			Server:      "",
   142  			DNSIP:       "10.0.0.0/24",
   143  			User:        "demo",
   144  			Password:    "supersecret",
   145  			Type:        "kerberos",
   146  			ID:          "3c829734-0679-4c17-9637-801da48c0d5f",
   147  		},
   148  	}
   149  
   150  	th.CheckDeepEquals(t, expected, actual)
   151  }
   152  
   153  // Verifies that it is possible to get a security service
   154  func TestGet(t *testing.T) {
   155  	th.SetupHTTP()
   156  	defer th.TeardownHTTP()
   157  
   158  	MockGetResponse(t)
   159  
   160  	var nilTime time.Time
   161  	expected := securityservices.SecurityService{
   162  		ID:          "3c829734-0679-4c17-9637-801da48c0d5f",
   163  		Name:        "SecServ1",
   164  		CreatedAt:   time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC),
   165  		Description: "Creating my first Security Service",
   166  		Type:        "kerberos",
   167  		UpdatedAt:   nilTime,
   168  		ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
   169  		Status:      "new",
   170  		Domain:      "",
   171  		Server:      "",
   172  		DNSIP:       "10.0.0.0/24",
   173  		User:        "demo",
   174  		Password:    "supersecret",
   175  	}
   176  
   177  	n, err := securityservices.Get(context.TODO(), client.ServiceClient(), "3c829734-0679-4c17-9637-801da48c0d5f").Extract()
   178  	th.AssertNoErr(t, err)
   179  
   180  	th.CheckDeepEquals(t, &expected, n)
   181  }
   182  
   183  // Verifies that it is possible to update a security service
   184  func TestUpdate(t *testing.T) {
   185  	th.SetupHTTP()
   186  	defer th.TeardownHTTP()
   187  
   188  	MockUpdateResponse(t)
   189  	expected := securityservices.SecurityService{
   190  		ID:          "securityServiceID",
   191  		Name:        "SecServ2",
   192  		CreatedAt:   time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC),
   193  		Description: "Updating my first Security Service",
   194  		Type:        "kerberos",
   195  		UpdatedAt:   time.Date(2015, 9, 7, 12, 20, 10, 0, time.UTC),
   196  		ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
   197  		Status:      "new",
   198  		Domain:      "",
   199  		Server:      "",
   200  		DNSIP:       "10.0.0.0/24",
   201  		User:        "demo",
   202  		Password:    "supersecret",
   203  	}
   204  
   205  	name := "SecServ2"
   206  	options := securityservices.UpdateOpts{Name: &name}
   207  	s, err := securityservices.Update(context.TODO(), client.ServiceClient(), "securityServiceID", options).Extract()
   208  	th.AssertNoErr(t, err)
   209  	th.CheckDeepEquals(t, &expected, s)
   210  }