-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(test): Support unit tests for IndexName validation #22
Merged
drmarjanovic
merged 5 commits into
main
from
test-support-unit-tests-for-index-name-validation
Dec 13, 2022
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
modules/library/src/test/scala/zio/elasticsearch/IndexNameSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package zio.elasticsearch | ||
|
||
import zio.prelude.Validation | ||
import zio.test.Assertion.equalTo | ||
import zio.test._ | ||
|
||
object IndexNameSpec extends ZIOSpecDefault { | ||
|
||
override def spec: Spec[TestEnvironment, Any] = | ||
suite("IndexName validation")( | ||
test("succeed for valid string") { | ||
dbulaja98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(IndexName.make("index-name"))(equalTo(Validation.succeed(IndexName("index-name")))) | ||
}, | ||
test("fail for string containing upper letter") { | ||
val invalidIndexStr = "Index-name" | ||
dbulaja98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(IndexName.make(invalidIndexStr))(equalTo(Validation.fail(validationFailedStr(invalidIndexStr)))) | ||
}, | ||
test("fail for string containing charachter '*'") { | ||
val invalidIndexStr = "index*name" | ||
assert(IndexName.make(invalidIndexStr))(equalTo(Validation.fail(validationFailedStr(invalidIndexStr)))) | ||
}, | ||
test("fail for string containing charachter ':'") { | ||
val invalidIndexStr = "index:name" | ||
assert(IndexName.make(invalidIndexStr))(equalTo(Validation.fail(validationFailedStr(invalidIndexStr)))) | ||
}, | ||
test("fail for string starting with charachter '-'") { | ||
val invalidIndexStr = "-index.name" | ||
assert(IndexName.make(invalidIndexStr))(equalTo(Validation.fail(validationFailedStr(invalidIndexStr)))) | ||
}, | ||
test("fail for string '.'") { | ||
val invalidIndexStr = "." | ||
assert(IndexName.make(invalidIndexStr))(equalTo(Validation.fail(validationFailedStr(invalidIndexStr)))) | ||
}, | ||
test("fail for string longer than 255 bytes") { | ||
checkN(5)(Gen.stringN(256)(Gen.alphaChar)) { invalidIndexStr => | ||
dbulaja98 marked this conversation as resolved.
Show resolved
Hide resolved
dbulaja98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val lowerCaseStr = invalidIndexStr.toLowerCase() | ||
assert(IndexName.make(lowerCaseStr.toLowerCase))( | ||
dbulaja98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
equalTo(Validation.fail(validationFailedStr(lowerCaseStr.toLowerCase))) | ||
) | ||
} | ||
} | ||
) | ||
|
||
private def validationFailedStr(indexStr: String): String = | ||
dbulaja98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
s"""$indexStr did not satisfy | ||
| - Must be lower case only | ||
| - Cannot include \\, /, *, ?, ", <, >, |, ` `(space character), `,`(comma), #. | ||
| - Cannot include ":"(since 7.0). | ||
| - Cannot start with -, _, +. | ||
| - Cannot be `.` or `..`. | ||
| - Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster). | ||
| - Names starting with . are deprecated, except for hidden indices and internal indices managed by plugins. | ||
|""".stripMargin | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess
IntegrationTest
extendsTest
? Can we useTest
here only?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think that
IntegrationTest
does not extendTest
.