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