Skip to content

Commit 343836e

Browse files
committed
Merge branch 'dev' of https://github.com/huangpf/azure-powershell into dev
1 parent 877045e commit 343836e

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

src/ServiceManagement/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380
<Compile Include="Resources\ResourceLocator.cs" />
381381
<Compile Include="Scheduler\SchedulerTests.cs" />
382382
<Compile Include="ServiceBusTests\ServiceBusAuthorizationRuleTests.cs" />
383+
<Compile Include="ServiceManagement\UnitTests.cs" />
383384
<Compile Include="ServiceManagement\ScenarioTests.cs" />
384385
<Compile Include="ServiceManagement\ServiceManagementTests.cs" />
385386
<Compile Include="StorageTests\StorageContainerTest.cs" />
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions;
16+
using System;
17+
using Xunit;
18+
19+
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
20+
{
21+
public partial class ServiceManagementTests
22+
{
23+
[Fact]
24+
[Trait(Category.Service, Category.ServiceManagement)]
25+
[Trait(Category.AcceptanceType, Category.CheckIn)]
26+
[Trait(Category.AcceptanceType, Category.BVT)]
27+
public void TestExtensionRoleNames()
28+
{
29+
var roleNames = new string[]
30+
{
31+
"test Role Name",
32+
"!!!!! _____ test Role Name ~~~",
33+
"testRoleName",
34+
" testRoleName",
35+
"testRoleName ",
36+
" testRoleName"
37+
};
38+
var expectedPrefixName = "testRoleName";
39+
var expectedExtensionId = "testRoleName-test-test-Ext-0";
40+
foreach (var roleName in roleNames)
41+
{
42+
ExtensionRole er = new ExtensionRole(roleName);
43+
Assert.Equal(er.PrefixName, expectedPrefixName);
44+
Assert.Equal(er.GetExtensionId("test", "test", 0), expectedExtensionId);
45+
}
46+
47+
var longRoleNames = new string[]
48+
{
49+
"A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789",
50+
" A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789 ~~~"
51+
};
52+
53+
// Extenion ID's Max Length 60 = 43 + 1 + 4 + 1 + 4 + 1 + 5
54+
// i.e. 'A123...E123' + '-' + 'test' + '-' + 'test' + '-' + 'Ext-0'
55+
// L=43 L=1 L=4 L=1 L=4 L=1 L=5
56+
expectedPrefixName = longRoleNames[0];
57+
expectedExtensionId = "A123456789B123456789C123456789D123456789E123-test-test-Ext-0";
58+
foreach (var roleName in longRoleNames)
59+
{
60+
ExtensionRole er = new ExtensionRole(roleName);
61+
Assert.Equal(er.PrefixName, expectedPrefixName);
62+
Assert.Equal(er.GetExtensionId("test", "test", 0), expectedExtensionId);
63+
}
64+
65+
66+
var longExtensionNames = longRoleNames;
67+
expectedExtensionId = "D-A123456789B123456789C123456789D123456789E123456-test-Ext-1";
68+
foreach (var extensionName in longExtensionNames)
69+
{
70+
ExtensionRole er = new ExtensionRole();
71+
Assert.Equal(er.PrefixName, "Default");
72+
Assert.Equal(er.GetExtensionId(extensionName, "test", 1), expectedExtensionId);
73+
}
74+
}
75+
}
76+
}

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionRole.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class ExtensionRole
2323
protected const string DefaultExtensionIdPrefixStr = "Default";
2424
protected const string ExtensionIdSuffixTemplate = "-{0}-{1}-Ext-{2}";
2525
protected const int MaxExtensionIdLength = 60;
26+
protected const int MaxSuffixLength = MaxExtensionIdLength - 1;
2627

2728
public string RoleName { get; private set; }
2829
public string PrefixName { get; private set; }
@@ -81,6 +82,12 @@ public string GetExtensionId(string extensionName, string slot, int index)
8182

8283
var suffix = new StringBuilder();
8384
suffix.AppendFormat(ExtensionIdSuffixTemplate, normalizedExtName, slot, index);
85+
if (suffix.Length > MaxSuffixLength)
86+
{
87+
int lenDiff = suffix.Length - MaxSuffixLength;
88+
int startIndex = 1; // Suffix starts with '-'
89+
suffix.Remove(startIndex + normalizedExtName.Length - lenDiff, lenDiff);
90+
}
8491

8592
int prefixSubStrLen = Math.Min(Math.Max(MaxExtensionIdLength - suffix.Length, 0), PrefixName.Length);
8693

0 commit comments

Comments
 (0)