Skip to content

Commit

Permalink
Update ImageNameTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Devashishbasu committed Jan 22, 2024
1 parent d07beb7 commit 1b17182
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.image;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -123,22 +123,23 @@ private void verifyData(Object[] data) {
@Test
void testIllegalFormat() {
assertThrows(IllegalArgumentException.class, () -> new ImageName(""));

}
@Test
void shouldThrowExceptionOnTooLongImageName() {
// New test for too long repository name
String tooLongName = generateTooLongImageName();
assertThatIllegalArgumentException()
.as("Too long image name should fail")
.isThrownBy(() -> new ImageName(tooLongName))
.withMessageContaining("Repository name must not be more than 255 characters");

}

private String generateTooLongImageName() {
StringBuilder tooLongName = new StringBuilder();
int maxLength = 255 + 1; // exceeding the maximum length
for (int i = 0; i < maxLength; i++) {
tooLongName.append("a");
}
return tooLongName.toString();
char repeatedChar = 'a';
int maxLength = 255 + 1;
String tooLongName = StringUtils.repeat(repeatedChar, maxLength);
return tooLongName;
}

@Test
Expand Down

0 comments on commit 1b17182

Please sign in to comment.