1
- using System ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
3
2
using System . IO ;
4
3
using System . IO . Compression ;
5
4
using System . Linq ;
6
- using System . Net . Http ;
7
5
using System . Reflection ;
8
6
using System . Text ;
9
7
using System . Threading . Tasks ;
10
8
using System . Xml ;
11
9
using System . Xml . Linq ;
12
- using Azure . Identity ;
13
- using Azure . ResourceManager . Resources ;
14
10
using Azure . ResourceManager . Resources . Models ;
15
11
using Calamari . Azure ;
16
12
using Calamari . Common . Plumbing . FileSystem ;
@@ -281,12 +277,7 @@ private static (string packagePath, string packageName, string packageVersion) P
281
277
282
278
private void AddVariables ( CommandTestBuilderContext context )
283
279
{
284
- context . Variables . Add ( AccountVariables . ClientId , clientId ) ;
285
- context . Variables . Add ( AccountVariables . Password , clientSecret ) ;
286
- context . Variables . Add ( AccountVariables . TenantId , tenantId ) ;
287
- context . Variables . Add ( AccountVariables . SubscriptionId , subscriptionId ) ;
288
- context . Variables . Add ( "Octopus.Action.Azure.ResourceGroupName" , resourceGroupName ) ;
289
- context . Variables . Add ( "Octopus.Action.Azure.WebAppName" , site . Name ) ;
280
+ AddAzureVariables ( context ) ;
290
281
context . Variables . Add ( "Greeting" , greeting ) ;
291
282
context . Variables . Add ( KnownVariables . Package . EnabledFeatures , KnownVariables . Features . SubstituteInFiles ) ;
292
283
context . Variables . Add ( PackageVariables . SubstituteInFilesTargets , "index.html" ) ;
@@ -297,9 +288,6 @@ private void AddVariables(CommandTestBuilderContext context)
297
288
[ TestFixture ]
298
289
public class WhenUsingALinuxAppService : AppServiceIntegrationTest
299
290
{
300
- private string linuxServicePlanName ;
301
- private string functionAppSiteName ;
302
-
303
291
protected override async Task ConfigureTestResources ( ResourceGroup resourceGroup )
304
292
{
305
293
var storageClient = new StorageManagementClient ( new TokenCredentials ( authToken ) )
@@ -329,7 +317,7 @@ protected override async Task ConfigureTestResources(ResourceGroup resourceGroup
329
317
}
330
318
) ;
331
319
332
- var functionAppSite = await webMgmtClient . WebApps . BeginCreateOrUpdateAsync ( resourceGroupName ,
320
+ site = await webMgmtClient . WebApps . BeginCreateOrUpdateAsync ( resourceGroupName ,
333
321
$ "{ resourceGroupName } -linux",
334
322
new Site ( resourceGroupLocation )
335
323
{
@@ -350,9 +338,6 @@ protected override async Task ConfigureTestResources(ResourceGroup resourceGroup
350
338
}
351
339
}
352
340
) ;
353
-
354
- linuxServicePlanName = linuxSvcPlan . Name ;
355
- functionAppSiteName = functionAppSite . Name ;
356
341
}
357
342
358
343
[ Test ]
@@ -371,7 +356,7 @@ await CommandTestBuilder.CreateAsync<DeployAzureAppServiceCommand, Program>().Wi
371
356
// Assert
372
357
await DoWithRetries ( 10 , async ( ) =>
373
358
{
374
- await AssertContent ( $ "{ functionAppSiteName } .azurewebsites.net",
359
+ await AssertContent ( $ "{ site . Name } .azurewebsites.net",
375
360
rootPath : $ "api/HttpExample?name={ greeting } ",
376
361
actualText : $ "Hello, { greeting } ") ;
377
362
} ,
@@ -382,9 +367,9 @@ await AssertContent($"{functionAppSiteName}.azurewebsites.net",
382
367
public async Task CanDeployZip_ToLinuxFunctionApp_WithRunFromPackageFlag ( )
383
368
{
384
369
// Arrange
385
- var settings = await webMgmtClient . WebApps . ListApplicationSettingsAsync ( resourceGroupName , functionAppSiteName ) ;
370
+ var settings = await webMgmtClient . WebApps . ListApplicationSettingsAsync ( resourceGroupName , site . Name ) ;
386
371
settings . Properties [ "WEBSITE_RUN_FROM_PACKAGE" ] = "1" ;
387
- await webMgmtClient . WebApps . UpdateApplicationSettingsAsync ( resourceGroupName , functionAppSiteName , settings ) ;
372
+ await webMgmtClient . WebApps . UpdateApplicationSettingsAsync ( resourceGroupName , site . Name , settings ) ;
388
373
389
374
var packageInfo = PrepareZipPackage ( ) ;
390
375
@@ -398,7 +383,7 @@ await CommandTestBuilder.CreateAsync<DeployAzureAppServiceCommand, Program>().Wi
398
383
// Assert
399
384
await DoWithRetries ( 10 , async ( ) =>
400
385
{
401
- await AssertContent ( $ "{ functionAppSiteName } .azurewebsites.net",
386
+ await AssertContent ( $ "{ site . Name } .azurewebsites.net",
402
387
rootPath : $ "api/HttpExample?name={ greeting } ",
403
388
actualText : $ "Hello, { greeting } ") ;
404
389
} ,
@@ -428,104 +413,9 @@ private static (string packagePath, string packageName, string packageVersion) P
428
413
429
414
private void AddVariables ( CommandTestBuilderContext context )
430
415
{
431
- context . Variables . Add ( AccountVariables . ClientId , clientId ) ;
432
- context . Variables . Add ( AccountVariables . Password , clientSecret ) ;
433
- context . Variables . Add ( AccountVariables . TenantId , tenantId ) ;
434
- context . Variables . Add ( AccountVariables . SubscriptionId , subscriptionId ) ;
435
- context . Variables . Add ( "Octopus.Action.Azure.ResourceGroupName" , resourceGroupName ) ;
436
- context . Variables . Add ( "Octopus.Action.Azure.WebAppName" , functionAppSiteName ) ;
416
+ AddAzureVariables ( context ) ;
437
417
context . Variables . Add ( SpecialVariables . Action . Azure . DeploymentType , "ZipDeploy" ) ;
438
418
}
439
419
}
440
420
}
441
-
442
- public abstract class AppServiceIntegrationTest
443
- {
444
- protected string clientId ;
445
- protected string clientSecret ;
446
- protected string tenantId ;
447
- protected string subscriptionId ;
448
- protected string resourceGroupName ;
449
- protected string resourceGroupLocation ;
450
- protected string greeting = "Calamari" ;
451
- protected string authToken ;
452
- protected WebSiteManagementClient webMgmtClient ;
453
- protected Site site ;
454
-
455
- private ResourceGroupsOperations resourceGroupClient ;
456
- private readonly HttpClient client = new HttpClient ( ) ;
457
-
458
- [ OneTimeSetUp ]
459
- public async Task Setup ( )
460
- {
461
- var resourceManagementEndpointBaseUri =
462
- Environment . GetEnvironmentVariable ( AccountVariables . ResourceManagementEndPoint ) ??
463
- DefaultVariables . ResourceManagementEndpoint ;
464
- var activeDirectoryEndpointBaseUri =
465
- Environment . GetEnvironmentVariable ( AccountVariables . ActiveDirectoryEndPoint ) ??
466
- DefaultVariables . ActiveDirectoryEndpoint ;
467
-
468
- resourceGroupName = Guid . NewGuid ( ) . ToString ( ) ;
469
-
470
- clientId = ExternalVariables . Get ( ExternalVariable . AzureSubscriptionClientId ) ;
471
- clientSecret = ExternalVariables . Get ( ExternalVariable . AzureSubscriptionPassword ) ;
472
- tenantId = ExternalVariables . Get ( ExternalVariable . AzureSubscriptionTenantId ) ;
473
- subscriptionId = ExternalVariables . Get ( ExternalVariable . AzureSubscriptionId ) ;
474
- resourceGroupLocation = Environment . GetEnvironmentVariable ( "AZURE_NEW_RESOURCE_REGION" ) ?? "eastus" ;
475
-
476
- authToken = await Auth . GetAuthTokenAsync ( activeDirectoryEndpointBaseUri , resourceManagementEndpointBaseUri ,
477
- tenantId , clientId , clientSecret ) ;
478
-
479
- var resourcesClient = new ResourcesManagementClient ( subscriptionId ,
480
- new ClientSecretCredential ( tenantId , clientId , clientSecret ) ) ;
481
-
482
- resourceGroupClient = resourcesClient . ResourceGroups ;
483
-
484
- var resourceGroup = new ResourceGroup ( resourceGroupLocation ) ;
485
- resourceGroup = await resourceGroupClient . CreateOrUpdateAsync ( resourceGroupName , resourceGroup ) ;
486
-
487
- webMgmtClient = new WebSiteManagementClient ( new TokenCredentials ( authToken ) )
488
- {
489
- SubscriptionId = subscriptionId ,
490
- HttpClient = { BaseAddress = new Uri ( DefaultVariables . ResourceManagementEndpoint ) } ,
491
- } ;
492
-
493
- await ConfigureTestResources ( resourceGroup ) ;
494
- }
495
-
496
- protected abstract Task ConfigureTestResources ( ResourceGroup resourceGroup ) ;
497
-
498
- [ OneTimeTearDown ]
499
- public async Task Cleanup ( )
500
- {
501
- if ( resourceGroupClient != null )
502
- await resourceGroupClient . StartDeleteAsync ( resourceGroupName ) ;
503
- }
504
-
505
- protected async Task AssertContent ( string hostName , string actualText , string rootPath = null )
506
- {
507
- var result = await client . GetStringAsync ( $ "https://{ hostName } /{ rootPath } ") ;
508
-
509
- result . Should ( ) . Contain ( actualText ) ;
510
- }
511
-
512
- protected static async Task DoWithRetries ( int retries , Func < Task > action , int secondsBetweenRetries )
513
- {
514
- foreach ( var retry in Enumerable . Range ( 1 , retries ) )
515
- {
516
- try
517
- {
518
- await action ( ) ;
519
- break ;
520
- }
521
- catch
522
- {
523
- if ( retry == retries )
524
- throw ;
525
-
526
- await Task . Delay ( secondsBetweenRetries * 1000 ) ;
527
- }
528
- }
529
- }
530
- }
531
421
}
0 commit comments