| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 3 | | // license information. |
| | 4 | |
|
| | 5 | | namespace Microsoft.Azure.Management.Search.Tests |
| | 6 | | { |
| | 7 | | using System; |
| | 8 | | using System.Collections.Generic; |
| | 9 | | using System.Linq; |
| | 10 | | using System.Net; |
| | 11 | | using Microsoft.Azure.Management.Search.Models; |
| | 12 | | using Microsoft.Azure.Search.Tests.Utilities; |
| | 13 | | using Rest.Azure; |
| | 14 | | using Xunit; |
| | 15 | |
|
| | 16 | | public sealed class SearchServiceTests : SearchTestBase<ResourceGroupFixture> |
| | 17 | | { |
| | 18 | | private const string InvalidServiceName = "----badname"; |
| | 19 | |
|
| | 20 | | [Fact] |
| | 21 | | public void CanListServices() |
| | 22 | | { |
| 0 | 23 | | Run(() => |
| 0 | 24 | | { |
| 0 | 25 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 26 | |
|
| 0 | 27 | | SearchService service1 = CreateFreeService(searchMgmt); |
| 0 | 28 | | SearchService service2 = CreateFreeService(searchMgmt); |
| 0 | 29 | |
|
| 0 | 30 | | var services = searchMgmt.Services.ListByResourceGroup(Data.ResourceGroupName); |
| 0 | 31 | | Assert.NotNull(services); |
| 0 | 32 | | Assert.Equal(2, services.Count()); |
| 0 | 33 | | Assert.Contains(service1.Name, services.Select(s => s.Name)); |
| 0 | 34 | | Assert.Contains(service2.Name, services.Select(s => s.Name)); |
| 0 | 35 | | }); |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | [Fact] |
| | 39 | | public void CanListServicesBySubscription() |
| | 40 | | { |
| 0 | 41 | | Run(() => |
| 0 | 42 | | { |
| 0 | 43 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 44 | | SearchService service1 = CreateFreeService(searchMgmt); |
| 0 | 45 | | SearchService service2 = CreateFreeService(searchMgmt); |
| 0 | 46 | |
|
| 0 | 47 | | var services = searchMgmt.Services.ListBySubscription(); |
| 0 | 48 | | Assert.NotNull(services); |
| 0 | 49 | | Assert.Equal(2, services.Count()); |
| 0 | 50 | | Assert.Contains(service1.Name, services.Select(s => s.Name)); |
| 0 | 51 | | Assert.Contains(service2.Name, services.Select(s => s.Name)); |
| 0 | 52 | | }); |
| 0 | 53 | | } |
| | 54 | |
|
| | 55 | | [Fact] |
| | 56 | | public void CanCreateAndDeleteService() |
| | 57 | | { |
| 0 | 58 | | Run(() => |
| 0 | 59 | | { |
| 0 | 60 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 61 | | SearchService service = CreateFreeService(searchMgmt); |
| 0 | 62 | |
|
| 0 | 63 | | searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); |
| 0 | 64 | |
|
| 0 | 65 | | Assert.Empty(searchMgmt.Services.ListByResourceGroup(Data.ResourceGroupName)); |
| 0 | 66 | | }); |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | [Fact] |
| | 70 | | public void CanCreateAndGetService() |
| | 71 | | { |
| 0 | 72 | | Run(() => |
| 0 | 73 | | { |
| 0 | 74 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 75 | | SearchService originalService = CreateFreeService(searchMgmt); |
| 0 | 76 | |
|
| 0 | 77 | | SearchService service = searchMgmt.Services.Get(Data.ResourceGroupName, originalService.Name); |
| 0 | 78 | |
|
| 0 | 79 | | AssertServicesEqual(originalService, service); |
| 0 | 80 | | }); |
| 0 | 81 | | } |
| | 82 | |
|
| | 83 | | [Fact] |
| | 84 | | public void DeleteServiceIsIdempotent() |
| | 85 | | { |
| 0 | 86 | | Run(() => |
| 0 | 87 | | { |
| 0 | 88 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 89 | | SearchService service = CreateFreeService(searchMgmt); |
| 0 | 90 | |
|
| 0 | 91 | | searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); |
| 0 | 92 | | searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); |
| 0 | 93 | | }); |
| 0 | 94 | | } |
| | 95 | |
|
| | 96 | | [Fact] |
| | 97 | | public void CheckNameAvailabilitySucceedsOnNewName() |
| | 98 | | { |
| 0 | 99 | | Run(() => |
| 0 | 100 | | { |
| 0 | 101 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 102 | |
|
| 0 | 103 | | CheckNameAvailabilityOutput result = searchMgmt.Services.CheckNameAvailability("newservice"); |
| 0 | 104 | |
|
| 0 | 105 | | Assert.Null(result.Message); |
| 0 | 106 | | Assert.Null(result.Reason); |
| 0 | 107 | | Assert.True(result.IsNameAvailable); |
| 0 | 108 | | }); |
| 0 | 109 | | } |
| | 110 | |
|
| | 111 | | [Fact] |
| | 112 | | public void CheckNameAvailabilityFailsOnUsedName() |
| | 113 | | { |
| 0 | 114 | | Run(() => |
| 0 | 115 | | { |
| 0 | 116 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 117 | | SearchService service = CreateFreeService(searchMgmt); |
| 0 | 118 | |
|
| 0 | 119 | | CheckNameAvailabilityOutput result = searchMgmt.Services.CheckNameAvailability(service.Name); |
| 0 | 120 | |
|
| 0 | 121 | | Assert.Null(result.Message); |
| 0 | 122 | | Assert.Equal(UnavailableNameReason.AlreadyExists, result.Reason); |
| 0 | 123 | | Assert.False(result.IsNameAvailable); |
| 0 | 124 | | }); |
| 0 | 125 | | } |
| | 126 | |
|
| | 127 | | [Fact] |
| | 128 | | public void CheckNameAvailabilityFailsOnInvalidName() |
| | 129 | | { |
| 0 | 130 | | Run(() => |
| 0 | 131 | | { |
| 0 | 132 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 133 | |
|
| 0 | 134 | | CheckNameAvailabilityOutput result = |
| 0 | 135 | | searchMgmt.Services.CheckNameAvailability(InvalidServiceName); |
| 0 | 136 | |
|
| 0 | 137 | | Assert.False(string.IsNullOrEmpty(result.Message)); |
| 0 | 138 | | Assert.Equal(UnavailableNameReason.Invalid, result.Reason); |
| 0 | 139 | | Assert.False(result.IsNameAvailable); |
| 0 | 140 | | }); |
| 0 | 141 | | } |
| | 142 | |
|
| | 143 | | [Fact] |
| | 144 | | public void CanCreateBasicService() |
| | 145 | | { |
| 0 | 146 | | Run(() => TestCreateServiceForSku(SkuName.Basic)); |
| 0 | 147 | | } |
| | 148 | |
|
| | 149 | | [Fact] |
| | 150 | | public void CanCreateStandardService() |
| | 151 | | { |
| 0 | 152 | | Run(() => TestCreateServiceForSku(SkuName.Standard)); |
| 0 | 153 | | } |
| | 154 | |
|
| | 155 | | [Fact] |
| | 156 | | public void CanCreateStandard2Service() |
| | 157 | | { |
| 0 | 158 | | Run(() => TestCreateServiceForSku(SkuName.Standard2)); |
| 0 | 159 | | } |
| | 160 | |
|
| | 161 | | [Fact] |
| | 162 | | public void CanCreateStandard3Service() |
| | 163 | | { |
| 0 | 164 | | Run(() => |
| 0 | 165 | | { |
| 0 | 166 | | SearchService service = DefineServiceWithSku(SkuName.Standard3); |
| 0 | 167 | | service.HostingMode = HostingMode.Default; |
| 0 | 168 | |
|
| 0 | 169 | | TestCreateService(service); |
| 0 | 170 | | }); |
| 0 | 171 | | } |
| | 172 | |
|
| | 173 | | [Fact] |
| | 174 | | public void CanCreateStandard3HighDensityService() |
| | 175 | | { |
| 0 | 176 | | Run(() => |
| 0 | 177 | | { |
| 0 | 178 | | SearchService service = DefineServiceWithSku(SkuName.Standard3); |
| 0 | 179 | | service.HostingMode = HostingMode.HighDensity; |
| 0 | 180 | |
|
| 0 | 181 | | TestCreateService(service); |
| 0 | 182 | | }); |
| 0 | 183 | | } |
| | 184 | |
|
| | 185 | | [Fact] |
| | 186 | | public void CanCreateStorageOptimizedL1Service() |
| | 187 | | { |
| 0 | 188 | | Run(() => TestCreateServiceForSku(SkuName.StorageOptimizedL1)); |
| 0 | 189 | | } |
| | 190 | |
|
| | 191 | | [Fact] |
| | 192 | | public void CanCreateStorageOptimizedL2Service() |
| | 193 | | { |
| 0 | 194 | | Run(() => TestCreateServiceForSku(SkuName.StorageOptimizedL2)); |
| 0 | 195 | | } |
| | 196 | |
|
| | 197 | | [Fact] |
| | 198 | | public void CanScaleServiceUpAndDown() |
| | 199 | | { |
| 0 | 200 | | Run(() => |
| 0 | 201 | | { |
| 0 | 202 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 203 | | SearchService service = CreateServiceForSku(searchMgmt, SkuName.Standard); |
| 0 | 204 | |
|
| 0 | 205 | | WaitForProvisioningToComplete(searchMgmt, service); |
| 0 | 206 | |
|
| 0 | 207 | | // Scale up to 2 replicas x 2 partitions. |
| 0 | 208 | | service = |
| 0 | 209 | | searchMgmt.Services.Update( |
| 0 | 210 | | Data.ResourceGroupName, |
| 0 | 211 | | service.Name, |
| 0 | 212 | | new SearchService() { ReplicaCount = 2, PartitionCount = 2 }); |
| 0 | 213 | |
|
| 0 | 214 | | service = WaitForProvisioningToComplete(searchMgmt, service); |
| 0 | 215 | | Assert.Equal(2, service.ReplicaCount); |
| 0 | 216 | | Assert.Equal(2, service.PartitionCount); |
| 0 | 217 | |
|
| 0 | 218 | | // Scale back down to 1 replica x 1 partition. |
| 0 | 219 | | service = |
| 0 | 220 | | searchMgmt.Services.Update( |
| 0 | 221 | | Data.ResourceGroupName, |
| 0 | 222 | | service.Name, |
| 0 | 223 | | new SearchService() { ReplicaCount = 1, PartitionCount = 1 }); |
| 0 | 224 | |
|
| 0 | 225 | | service = WaitForProvisioningToComplete(searchMgmt, service); |
| 0 | 226 | | Assert.Equal(1, service.ReplicaCount); |
| 0 | 227 | | Assert.Equal(1, service.PartitionCount); |
| 0 | 228 | |
|
| 0 | 229 | | searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); |
| 0 | 230 | | }); |
| 0 | 231 | | } |
| | 232 | |
|
| | 233 | | [Fact] |
| | 234 | | public void CreateStandardServicePollsAutomatically() |
| | 235 | | { |
| 0 | 236 | | Run(() => |
| 0 | 237 | | { |
| 0 | 238 | | // Create an S1 with multiple replicas so that the operation will take some time. |
| 0 | 239 | | SearchService service = DefineServiceWithSku(SkuName.Standard); |
| 0 | 240 | | service.ReplicaCount = 2; |
| 0 | 241 | |
|
| 0 | 242 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 243 | | string serviceName = SearchTestUtilities.GenerateServiceName(); |
| 0 | 244 | |
|
| 0 | 245 | | service = searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service); |
| 0 | 246 | |
|
| 0 | 247 | | // Unlike BeginCreateOrUpdate, CreateOrUpdate should have already polled until |
| 0 | 248 | | // provisioning is complete. |
| 0 | 249 | | Assert.Equal(Models.ProvisioningState.Succeeded, service.ProvisioningState); |
| 0 | 250 | | Assert.Equal(SearchServiceStatus.Running, service.Status); |
| 0 | 251 | |
|
| 0 | 252 | | searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); |
| 0 | 253 | | }); |
| 0 | 254 | | } |
| | 255 | |
|
| | 256 | | [Fact] |
| | 257 | | public void CanUpdateTags() |
| | 258 | | { |
| 0 | 259 | | Run(() => |
| 0 | 260 | | { |
| 0 | 261 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 262 | | SearchService service = CreateFreeService(searchMgmt); |
| 0 | 263 | |
|
| 0 | 264 | | var testTags = |
| 0 | 265 | | new Dictionary<string, string>() |
| 0 | 266 | | { |
| 0 | 267 | | ["testTag"] = "testValue", |
| 0 | 268 | | ["anotherTag"] = "anotherValue" |
| 0 | 269 | | }; |
| 0 | 270 | |
|
| 0 | 271 | | // Add some tags. |
| 0 | 272 | | service = |
| 0 | 273 | | searchMgmt.Services.Update( |
| 0 | 274 | | Data.ResourceGroupName, |
| 0 | 275 | | service.Name, |
| 0 | 276 | | new SearchService() { Tags = testTags }); |
| 0 | 277 | |
|
| 0 | 278 | | Assert.Equal(testTags, service.Tags); |
| 0 | 279 | |
|
| 0 | 280 | | // Modify a tag. |
| 0 | 281 | | testTags["anotherTag"] = "differentValue"; |
| 0 | 282 | |
|
| 0 | 283 | | service = |
| 0 | 284 | | searchMgmt.Services.Update( |
| 0 | 285 | | Data.ResourceGroupName, |
| 0 | 286 | | service.Name, |
| 0 | 287 | | new SearchService() { Tags = testTags }); |
| 0 | 288 | |
|
| 0 | 289 | | Assert.Equal(testTags, service.Tags); |
| 0 | 290 | |
|
| 0 | 291 | | // Remove the second tag. |
| 0 | 292 | | testTags.Remove("anotherTag"); |
| 0 | 293 | |
|
| 0 | 294 | | service = |
| 0 | 295 | | searchMgmt.Services.Update( |
| 0 | 296 | | Data.ResourceGroupName, |
| 0 | 297 | | service.Name, |
| 0 | 298 | | new SearchService() { Tags = testTags }); |
| 0 | 299 | |
|
| 0 | 300 | | Assert.Equal(testTags, service.Tags); |
| 0 | 301 | | }); |
| 0 | 302 | | } |
| | 303 | |
|
| | 304 | | [Fact] |
| | 305 | | public void UpdatingImmutablePropertiesThrowsCloudException() |
| | 306 | | { |
| 0 | 307 | | Run(() => |
| 0 | 308 | | { |
| 0 | 309 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 310 | | SearchService service = CreateFreeService(searchMgmt); |
| 0 | 311 | |
|
| 0 | 312 | | CloudException e = |
| 0 | 313 | | Assert.Throws<CloudException>(() => |
| 0 | 314 | | searchMgmt.Services.Update( |
| 0 | 315 | | Data.ResourceGroupName, |
| 0 | 316 | | service.Name, |
| 0 | 317 | | new SearchService() { HostingMode = HostingMode.HighDensity })); |
| 0 | 318 | |
|
| 0 | 319 | | Assert.Equal("Updating HostingMode of an existing search service is not allowed.", e.Message); |
| 0 | 320 | |
|
| 0 | 321 | | // There is currently a validation bug in the Azure Search management API, so we can't |
| 0 | 322 | | // test for an exception yet. Instead, just make sure the location doesn't actually change. |
| 0 | 323 | | SearchService updatedService = |
| 0 | 324 | | searchMgmt.Services.Update( |
| 0 | 325 | | Data.ResourceGroupName, |
| 0 | 326 | | service.Name, |
| 0 | 327 | | new SearchService() { Location = "East US" }); // We run live tests in West US. |
| 0 | 328 | |
|
| 0 | 329 | | Assert.Equal(service.Location, updatedService.Location); |
| 0 | 330 | |
|
| 0 | 331 | | /*e = |
| 0 | 332 | | Assert.Throws<CloudException>(() => |
| 0 | 333 | | searchMgmt.Services.Update( |
| 0 | 334 | | Data.ResourceGroupName, |
| 0 | 335 | | service.Name, |
| 0 | 336 | | new SearchService() { Location = "East US" })); // We run live tests in West US. |
| 0 | 337 | |
|
| 0 | 338 | | Assert.Equal("Updating Location of an existing search service is not allowed.", e.Message);*/ |
| 0 | 339 | |
|
| 0 | 340 | | e = |
| 0 | 341 | | Assert.Throws<CloudException>(() => |
| 0 | 342 | | searchMgmt.Services.Update( |
| 0 | 343 | | Data.ResourceGroupName, |
| 0 | 344 | | service.Name, |
| 0 | 345 | | new SearchService() { Sku = new Sku(SkuName.Basic) })); |
| 0 | 346 | |
|
| 0 | 347 | | Assert.Equal("Updating Sku of an existing search service is not allowed.", e.Message); |
| 0 | 348 | | }); |
| 0 | 349 | | } |
| | 350 | |
|
| | 351 | | [Fact] |
| | 352 | | public void CreateServiceWithInvalidNameGivesUsefulMessage() |
| | 353 | | { |
| 0 | 354 | | Run(() => |
| 0 | 355 | | { |
| 0 | 356 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 357 | | SearchService service = DefineServiceWithSku(SkuName.Free); |
| 0 | 358 | |
|
| 0 | 359 | | CloudException e = |
| 0 | 360 | | Assert.Throws<CloudException>(() => |
| 0 | 361 | | searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, InvalidServiceName, service)); |
| 0 | 362 | |
|
| 0 | 363 | | string expectedMessage = |
| 0 | 364 | | $"Service name '{InvalidServiceName}' is invalid: Service name must only contain " + |
| 0 | 365 | | "lowercase letters, digits or dashes, cannot start or end with or contain consecutive " + |
| 0 | 366 | | "dashes and is limited to 60 characters."; |
| 0 | 367 | |
|
| 0 | 368 | | Assert.Equal(expectedMessage, e.Message); |
| 0 | 369 | | }); |
| 0 | 370 | | } |
| | 371 | |
|
| | 372 | | [Fact] |
| | 373 | | public void UpdateServiceWithInvalidNameGivesNotFound() |
| | 374 | | { |
| 0 | 375 | | Run(() => |
| 0 | 376 | | { |
| 0 | 377 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 378 | |
|
| 0 | 379 | | CloudException e = |
| 0 | 380 | | Assert.Throws<CloudException>(() => |
| 0 | 381 | | searchMgmt.Services.Update(Data.ResourceGroupName, "missing", new SearchService())); |
| 0 | 382 | |
|
| 0 | 383 | | Assert.Equal(HttpStatusCode.NotFound, e.Response.StatusCode); |
| 0 | 384 | | }); |
| 0 | 385 | | } |
| | 386 | |
|
| | 387 | | [Fact] |
| | 388 | | public void CanCreateServiceWithIdentity() |
| | 389 | | { |
| 0 | 390 | | Run(() => |
| 0 | 391 | | { |
| 0 | 392 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 393 | | string serviceName = SearchTestUtilities.GenerateServiceName(); |
| 0 | 394 | | SearchService service = DefineServiceWithSku(SkuName.Basic); |
| 0 | 395 | | service.Identity = new Identity(IdentityType.SystemAssigned); |
| 0 | 396 | | service = searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service); |
| 0 | 397 | | Assert.NotNull(service); |
| 0 | 398 | | Assert.NotNull(service.Identity); |
| 0 | 399 | | Assert.Equal(IdentityType.SystemAssigned, service.Identity.Type); |
| 0 | 400 | |
|
| 0 | 401 | | string principalId = string.IsNullOrWhiteSpace(service.Identity.PrincipalId) ? null : service.Identity.P |
| 0 | 402 | | Assert.NotNull(principalId); |
| 0 | 403 | |
|
| 0 | 404 | | string tenantId = string.IsNullOrWhiteSpace(service.Identity.TenantId) ? null : service.Identity.TenantI |
| 0 | 405 | | Assert.NotNull(tenantId); |
| 0 | 406 | |
|
| 0 | 407 | | searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); |
| 0 | 408 | | }); |
| 0 | 409 | | } |
| | 410 | |
|
| | 411 | | [Fact] |
| | 412 | | public void CanAddAndRemoveServiceIdentity() |
| | 413 | | { |
| 0 | 414 | | Run(() => |
| 0 | 415 | | { |
| 0 | 416 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 417 | | string serviceName = SearchTestUtilities.GenerateServiceName(); |
| 0 | 418 | | SearchService service = DefineServiceWithSku(SkuName.Basic); |
| 0 | 419 | | service.Identity = null; |
| 0 | 420 | | service = searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service); |
| 0 | 421 | | Assert.NotNull(service); |
| 0 | 422 | | Assert.Equal(IdentityType.None, service.Identity?.Type ?? IdentityType.None); |
| 0 | 423 | |
|
| 0 | 424 | | // assign an identity of type 'SystemAssigned' |
| 0 | 425 | | service.Identity = new Identity(IdentityType.SystemAssigned); |
| 0 | 426 | | service = searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, service); |
| 0 | 427 | | Assert.NotNull(service); |
| 0 | 428 | | Assert.NotNull(service.Identity); |
| 0 | 429 | | Assert.Equal(IdentityType.SystemAssigned, service.Identity.Type); |
| 0 | 430 | |
|
| 0 | 431 | | string principalId = string.IsNullOrWhiteSpace(service.Identity.PrincipalId) ? null : service.Identity.P |
| 0 | 432 | | Assert.NotNull(principalId); |
| 0 | 433 | |
|
| 0 | 434 | | string tenantId = string.IsNullOrWhiteSpace(service.Identity.TenantId) ? null : service.Identity.TenantI |
| 0 | 435 | | Assert.NotNull(tenantId); |
| 0 | 436 | |
|
| 0 | 437 | | // remove the identity by setting it's type to 'None' |
| 0 | 438 | | service.Identity.Type = IdentityType.None; |
| 0 | 439 | | service = searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, service); |
| 0 | 440 | | Assert.NotNull(service); |
| 0 | 441 | | Assert.Equal(IdentityType.None, service.Identity?.Type ?? IdentityType.None); |
| 0 | 442 | |
|
| 0 | 443 | | searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); |
| 0 | 444 | | }); |
| 0 | 445 | | } |
| | 446 | |
|
| | 447 | | [Fact] |
| | 448 | | public void CannotCreateOrUpdateFreeServiceWithIdentity() |
| | 449 | | { |
| 0 | 450 | | Run(() => |
| 0 | 451 | | { |
| 0 | 452 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 453 | |
|
| 0 | 454 | | string serviceName = SearchTestUtilities.GenerateServiceName(); |
| 0 | 455 | | SearchService service = DefineServiceWithSku(SkuName.Free); |
| 0 | 456 | | service.Identity = new Identity(IdentityType.SystemAssigned); |
| 0 | 457 | |
|
| 0 | 458 | | CloudException e = Assert.Throws<CloudException>(() => |
| 0 | 459 | | searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service)); |
| 0 | 460 | |
|
| 0 | 461 | | Assert.Equal("Resource identity is not supported for the selected SKU", e.Message); |
| 0 | 462 | |
|
| 0 | 463 | | // retry create without identity |
| 0 | 464 | | service.Identity = null; |
| 0 | 465 | | service = searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service); |
| 0 | 466 | | Assert.NotNull(service); |
| 0 | 467 | | Assert.Null(service.Identity); |
| 0 | 468 | |
|
| 0 | 469 | | // try update the created service by defining an identity |
| 0 | 470 | | service.Identity = new Identity(); |
| 0 | 471 | | e = Assert.Throws<CloudException>(() => |
| 0 | 472 | | searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, service)); |
| 0 | 473 | |
|
| 0 | 474 | | Assert.Equal("Resource identity is not supported for the selected SKU", e.Message); |
| 0 | 475 | | searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); |
| 0 | 476 | | }); |
| 0 | 477 | | } |
| | 478 | |
|
| | 479 | | [Fact] |
| | 480 | | public void CanCreateServiceInPrivateMode() |
| | 481 | | { |
| 0 | 482 | | Run(() => |
| 0 | 483 | | { |
| 0 | 484 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 485 | | CreateServiceForSkuWithDefinitionTemplate(searchMgmt, SkuName.Basic, DefineServiceWithSkuInPrivateMode); |
| 0 | 486 | | }); |
| 0 | 487 | | } |
| | 488 | |
|
| | 489 | | private static void AssertServicesEqual(SearchService a, SearchService b) => |
| 0 | 490 | | Assert.Equal(a, b, new ModelComparer<SearchService>()); |
| | 491 | |
|
| | 492 | | private SearchService DefineServiceWithSku(SkuName sku) |
| | 493 | | { |
| 0 | 494 | | return new SearchService() |
| 0 | 495 | | { |
| 0 | 496 | | Location = "EastUS", |
| 0 | 497 | | Sku = new Sku() { Name = sku }, |
| 0 | 498 | | ReplicaCount = 1, |
| 0 | 499 | | PartitionCount = 1 |
| 0 | 500 | | }; |
| | 501 | | } |
| | 502 | |
|
| | 503 | | private SearchService DefineServiceWithSkuInPrivateMode(SkuName sku) |
| | 504 | | { |
| 0 | 505 | | return new SearchService() |
| 0 | 506 | | { |
| 0 | 507 | | Location = "EastUS", |
| 0 | 508 | | Sku = new Sku() { Name = sku }, |
| 0 | 509 | | ReplicaCount = 1, |
| 0 | 510 | | PartitionCount = 1, |
| 0 | 511 | | PublicNetworkAccess = PublicNetworkAccess.Disabled |
| 0 | 512 | | }; |
| | 513 | | } |
| | 514 | |
|
| | 515 | | private SearchService CreateServiceForSku(SearchManagementClient searchMgmt, SkuName sku) |
| | 516 | | { |
| 0 | 517 | | string serviceName = SearchTestUtilities.GenerateServiceName(); |
| | 518 | |
|
| 0 | 519 | | SearchService service = DefineServiceWithSku(sku); |
| | 520 | |
|
| 0 | 521 | | service = searchMgmt.Services.BeginCreateOrUpdate(Data.ResourceGroupName, serviceName, service); |
| 0 | 522 | | Assert.NotNull(service); |
| | 523 | |
|
| 0 | 524 | | return service; |
| | 525 | | } |
| | 526 | |
|
| | 527 | | private delegate SearchService SearchServiceDefinition(SkuName sku); |
| | 528 | |
|
| | 529 | | private SearchService CreateServiceForSkuWithDefinitionTemplate(SearchManagementClient searchMgmt, SkuName sku, |
| | 530 | | { |
| 0 | 531 | | string serviceName = SearchTestUtilities.GenerateServiceName(); |
| | 532 | |
|
| 0 | 533 | | SearchService service = searchServiceDefinition(sku); |
| | 534 | |
|
| 0 | 535 | | service = searchMgmt.Services.BeginCreateOrUpdate(Data.ResourceGroupName, serviceName, service); |
| 0 | 536 | | Assert.NotNull(service); |
| | 537 | |
|
| 0 | 538 | | return service; |
| | 539 | | } |
| | 540 | |
|
| | 541 | | private SearchService CreateFreeService(SearchManagementClient searchMgmt) => |
| 0 | 542 | | CreateServiceForSku(searchMgmt, SkuName.Free); |
| | 543 | |
|
| | 544 | | private void TestCreateService(SearchService service) |
| | 545 | | { |
| 0 | 546 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 547 | | string serviceName = SearchTestUtilities.GenerateServiceName(); |
| | 548 | |
|
| 0 | 549 | | service = searchMgmt.Services.BeginCreateOrUpdate(Data.ResourceGroupName, serviceName, service); |
| 0 | 550 | | service = WaitForProvisioningToComplete(searchMgmt, service); |
| | 551 | |
|
| 0 | 552 | | searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); |
| 0 | 553 | | } |
| | 554 | |
|
| | 555 | | private SearchService WaitForProvisioningToComplete( |
| | 556 | | SearchManagementClient searchMgmt, |
| | 557 | | SearchService service) |
| | 558 | | { |
| 0 | 559 | | while (service.ProvisioningState == Models.ProvisioningState.Provisioning) |
| | 560 | | { |
| 0 | 561 | | Assert.Equal(SearchServiceStatus.Provisioning, service.Status); |
| | 562 | |
|
| 0 | 563 | | SearchTestUtilities.WaitForServiceProvisioning(); |
| 0 | 564 | | service = searchMgmt.Services.Get(Data.ResourceGroupName, service.Name); |
| | 565 | | } |
| | 566 | |
|
| 0 | 567 | | Assert.Equal(Models.ProvisioningState.Succeeded, service.ProvisioningState); |
| 0 | 568 | | Assert.Equal(SearchServiceStatus.Running, service.Status); |
| 0 | 569 | | return service; |
| | 570 | | } |
| | 571 | |
|
| 0 | 572 | | private void TestCreateServiceForSku(SkuName sku) => TestCreateService(DefineServiceWithSku(sku)); |
| | 573 | | } |
| | 574 | | } |