fix JobTests#testEquals_noId by fixing regex expression and including `-`
Original commit: elastic/x-pack-elasticsearch@b295d5f621
This commit is contained in:
parent
8b135226f6
commit
999a1eb234
|
@ -718,7 +718,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContent
|
|||
id = this.id;
|
||||
} else {
|
||||
// Base64 UUIDs are not necessarily valid job IDs
|
||||
id = "auto-" + UUIDs.base64UUID().toLowerCase(Locale.ROOT).replaceAll("/\\+=", "_");
|
||||
id = "auto-" + UUIDs.base64UUID().toLowerCase(Locale.ROOT).replaceAll("[/+=-]", "_");
|
||||
if (id.endsWith("_")) {
|
||||
// Job IDs cannot end with underscores
|
||||
id = id.substring(0, id.length() - 1) + "z";
|
||||
|
@ -739,7 +739,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContent
|
|||
throw new IllegalArgumentException(Messages.getMessage(Messages.JOB_CONFIG_ID_TOO_LONG, MAX_JOB_ID_LENGTH));
|
||||
}
|
||||
if (!PrelertStrings.isValidId(id)) {
|
||||
throw new IllegalArgumentException(Messages.getMessage(Messages.INVALID_ID, ID.getPreferredName()));
|
||||
throw new IllegalArgumentException(Messages.getMessage(Messages.INVALID_ID, ID.getPreferredName(), id));
|
||||
}
|
||||
|
||||
if (Strings.isNullOrEmpty(indexName)) {
|
||||
|
|
|
@ -10,7 +10,7 @@ datastore.error.deleting = Error deleting index ''{0}''
|
|||
datastore.error.deleting.missing.index = Cannot delete job - no index with id ''{0}'' in the database
|
||||
datastore.error.executing.script = Error executing script ''{0}''
|
||||
|
||||
invalid.id = Invalid {0}; must be lowercase alphanumeric, may contain hyphens or underscores, may not start with underscore
|
||||
invalid.id = Invalid {0}; ''{1}'' must be lowercase alphanumeric, may contain hyphens or underscores, may not start with underscore
|
||||
|
||||
license.limit.detectors = Cannot create new job - your license limits you to {0,number,integer} detector(s), but you have configured {1,number,integer}.
|
||||
license.limit.detectors.reactivate = Cannot reactivate job with id ''{0}'' - your license limits you to {1,number,integer} concurrently running detectors. You must close a job before you can reactivate another.
|
||||
|
|
|
@ -242,9 +242,9 @@ public class JobTests extends AbstractSerializingTestCase<Job> {
|
|||
public void testCheckValidId_ProhibitedChars() {
|
||||
String invalidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()+?\"'~±/\\[]{},<>=";
|
||||
Job.Builder builder = buildJobBuilder("foo");
|
||||
String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName());
|
||||
for (char c : invalidChars.toCharArray()) {
|
||||
builder.setId(Character.toString(c));
|
||||
String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName(), Character.toString(c));
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals(errorMessage, e.getMessage());
|
||||
}
|
||||
|
@ -252,14 +252,14 @@ public class JobTests extends AbstractSerializingTestCase<Job> {
|
|||
|
||||
public void testCheckValidId_startsWithUnderscore() {
|
||||
Job.Builder builder = buildJobBuilder("_foo");
|
||||
String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName());
|
||||
String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName(), "_foo");
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals(errorMessage, e.getMessage());
|
||||
}
|
||||
|
||||
public void testCheckValidId_endsWithUnderscore() {
|
||||
Job.Builder builder = buildJobBuilder("foo_");
|
||||
String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName());
|
||||
String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName(), "foo_");
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals(errorMessage, e.getMessage());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue