|
8 | 8 |
|
9 | 9 | import unittest |
10 | 10 | import os |
| 11 | +import re |
11 | 12 | from pytest import skip |
12 | 13 | import requests |
13 | 14 | from knack.util import CLIError |
@@ -1369,6 +1370,58 @@ def test_webapp_up_track_runtimestatus_runtimefailed(self, resource_group): |
1369 | 1370 | import shutil |
1370 | 1371 | shutil.rmtree(temp_dir) |
1371 | 1372 |
|
| 1373 | + @live_only() |
| 1374 | + @AllowLargeResponse(8192) |
| 1375 | + @ResourceGroupPreparer(random_name_length=24, name_prefix='clitest', location=LINUX_ASP_LOCATION_WEBAPP) |
| 1376 | + def test_webapp_up_with_domain_name_scope(self, resource_group): |
| 1377 | + plan = self.create_random_name('up-dnlplan', 24) |
| 1378 | + webapp_name = self.create_random_name('up-dnl-app', 24) |
| 1379 | + zip_file_name = os.path.join(TEST_DIR, 'node-Express-up.zip') |
| 1380 | + |
| 1381 | + import zipfile |
| 1382 | + import tempfile |
| 1383 | + temp_dir = tempfile.mkdtemp() |
| 1384 | + zip_ref = zipfile.ZipFile(zip_file_name, 'r') |
| 1385 | + zip_ref.extractall(temp_dir) |
| 1386 | + current_working_dir = os.getcwd() |
| 1387 | + |
| 1388 | + up_working_dir = os.path.join(temp_dir, 'myExpressApp') |
| 1389 | + os.chdir(up_working_dir) |
| 1390 | + |
| 1391 | + # test dryrun with --domain-name-scope |
| 1392 | + result = self.cmd('webapp up -n {} --dryrun --domain-name-scope TenantReuse'.format( |
| 1393 | + webapp_name)).get_output_in_json() |
| 1394 | + self.assertTrue(result['name'].startswith(webapp_name)) |
| 1395 | + self.assertIn("node|", result['runtime_version'].lower()) |
| 1396 | + self.assertEqual(result['os'].lower(), 'linux') |
| 1397 | + |
| 1398 | + # test the full E2E operation works |
| 1399 | + self.cmd('webapp up -n {} -g {} --plan {} --domain-name-scope TenantReuse'.format( |
| 1400 | + webapp_name, resource_group, plan)).get_output_in_json() |
| 1401 | + |
| 1402 | + # Verify app is created with domain name scope |
| 1403 | + result = self.cmd('webapp show -n {} -g {}'.format(webapp_name, resource_group), checks=[ |
| 1404 | + JMESPathCheck('name', webapp_name), |
| 1405 | + JMESPathCheck('state', 'Running'), |
| 1406 | + JMESPathCheck('resourceGroup', resource_group), |
| 1407 | + JMESPathCheck('autoGeneratedDomainNameLabelScope', 'TenantReuse') |
| 1408 | + ]).get_output_in_json() |
| 1409 | + |
| 1410 | + # Verify the default hostname matches the regional pattern with hash |
| 1411 | + default_hostname = result.get('defaultHostName') |
| 1412 | + pattern = r'^([a-zA-Z0-9\-]+)-([a-z0-9]{16})\.([a-z]+-\d{2})\.azurewebsites\.net$' |
| 1413 | + match = re.match(pattern, default_hostname) |
| 1414 | + self.assertIsNotNone(match, "defaultHostName '{}' does not match expected pattern".format(default_hostname)) |
| 1415 | + app_name, hash_part, region = match.groups() |
| 1416 | + self.assertTrue(len(hash_part) == 16 and hash_part.islower(), "Hash is not 16 chars or not lowercase.") |
| 1417 | + self.assertIn('-', region, "Region part does not have '-' separator.") |
| 1418 | + self.assertEqual(app_name, webapp_name, "App name and defaultHostName app name do not match.") |
| 1419 | + |
| 1420 | + # cleanup |
| 1421 | + os.chdir(current_working_dir) |
| 1422 | + import shutil |
| 1423 | + shutil.rmtree(temp_dir) |
| 1424 | + |
1372 | 1425 |
|
1373 | 1426 | if __name__ == '__main__': |
1374 | 1427 | unittest.main() |
0 commit comments