@@ -2520,12 +2520,14 @@ private void runGetNextVmHostAndDisplayNameGeneratesCorrectHostAndDisplayNameFor
25202520 when (asVmGroupMock .getNextVmSeq ()).thenReturn (1L );
25212521 when (templateMock .getGuestOSId ()).thenReturn (1L );
25222522 Pair <String , String > result = autoScaleManagerImplSpy .getNextVmHostAndDisplayName (asVmGroupMock , templateMock );
2523- String vmHostNamePattern = AutoScaleManagerImpl .VM_HOSTNAME_PREFIX + vmGroupName +
2524- "-" + asVmGroupMock .getNextVmSeq () + "-[a-z]{6}" ;
2525- Assert .assertTrue (result .second ().matches (vmHostNamePattern ));
2523+ String vmHostNamePattern = AutoScaleManagerImpl .WINDOWS_VM_HOSTNAME_PREFIX + "[a-z]{6}" ;
2524+ Assert .assertTrue (result .first ().matches (vmHostNamePattern ));
25262525 Assert .assertEquals (15 , result .first ().length ());
2527- Assert .assertTrue (result .second ().endsWith (result .first ()));
2528-
2526+ String vmDisplayHostNamePattern = AutoScaleManagerImpl .VM_HOSTNAME_PREFIX + vmGroupName +
2527+ "-" + asVmGroupMock .getNextVmSeq () + "-[a-z]{6}" ;
2528+ Assert .assertTrue (result .second ().matches (vmDisplayHostNamePattern ));
2529+ Assert .assertTrue (result .second ().length () <= 63 );
2530+ Assert .assertTrue (result .second ().endsWith (result .first ().split ("-" )[2 ]));
25292531 }
25302532
25312533 @ Test
@@ -2565,57 +2567,4 @@ public void getNextVmHostAndDisplayNameHandlesNullGuestOS() {
25652567 Assert .assertTrue (result .first ().matches (vmHostNamePattern ));
25662568 Assert .assertEquals (result .first (), result .second ());
25672569 }
2568-
2569- @ Test
2570- public void trimsValidWindowsHostName () {
2571- AutoScaleManagerImpl manager = new AutoScaleManagerImpl ();
2572- String result = manager .getTrimmedHostNameForWindows ("ValidVMName1234" );
2573- Assert .assertEquals ("ValidVMName1234" , result );
2574- }
2575-
2576- @ Test
2577- public void trimsInvalidCharactersFromHostName () {
2578- AutoScaleManagerImpl manager = new AutoScaleManagerImpl ();
2579- String result = manager .getTrimmedHostNameForWindows ("Invalid@Host#Name!" );
2580- Assert .assertEquals ("InvalidHostName" , result );
2581- }
2582-
2583- @ Test
2584- public void ensuresHostNameStartsWithLetter () {
2585- AutoScaleManagerImpl manager = new AutoScaleManagerImpl ();
2586- String result = manager .getTrimmedHostNameForWindows ("123456789012345" );
2587- Assert .assertTrue (Character .isLetter (result .charAt (0 )));
2588- }
2589-
2590- @ Test
2591- public void prefixesWithLetterIfNoLetterExists () {
2592- AutoScaleManagerImpl manager = new AutoScaleManagerImpl ();
2593- String result = manager .getTrimmedHostNameForWindows ("1234567890-12345" );
2594- Assert .assertEquals ("a34567890-12345" , result );
2595- }
2596-
2597- @ Test
2598- public void trimsHostNameToLastMaxCharacters () {
2599- String name = "ThisIsAReallyLongHost-Name_1234" ;
2600- AutoScaleManagerImpl manager = new AutoScaleManagerImpl ();
2601- String result = manager .getTrimmedHostNameForWindows (name );
2602- String normalized = name .replace ("_" , "" );
2603- Assert .assertEquals (normalized
2604- .substring (normalized .length () - AutoScaleManagerImpl .MAX_WINDOWS_VM_HOSTNAME_LENGTH ),
2605- result );
2606- }
2607-
2608- @ Test
2609- public void handlesEmptyHostName () {
2610- AutoScaleManagerImpl manager = new AutoScaleManagerImpl ();
2611- String result = manager .getTrimmedHostNameForWindows ("" );
2612- Assert .assertEquals ("" , result );
2613- }
2614-
2615- @ Test
2616- public void handlesHostNameWithOnlyMostlyInvalidCharacters () {
2617- AutoScaleManagerImpl manager = new AutoScaleManagerImpl ();
2618- String result = manager .getTrimmedHostNameForWindows ("@#$%^&*() 1" );
2619- Assert .assertEquals ("a1" , result );
2620- }
26212570}
0 commit comments