Skip to content
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

Refactor IndexName tests #256

Merged
merged 4 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object IndexNameValidation {
params.exists(StringUtils.contains(string, _))

name.toLowerCase == name &&
name.nonEmpty &&
!startsWithAny(name, "+", "-", "_") &&
!containsAny(string = name, params = Chunk("*", "?", "\"", "<", ">", "|", " ", ",", "#", ":")) &&
!equalsAny(name, ".", "..") &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,53 @@ import zio.test._

object IndexNameSpec extends ZIOSpecDefault {
def spec: Spec[TestEnvironment, Any] =
suite("IndexName validation")(
test("succeed for valid string") {
check(genString(1, 255)) { name =>
assert(IndexName.make(name))(equalTo(Validation.succeed(unsafeWrap(name)(IndexName))))
}
},
test("fail for string containing upper letter") {
check(genString(0, 127), genString(0, 128)) { (part1, part2) =>
val invalidName = s"${part1}A$part2"
suite("IndexName")(
suite("constructing") (
test("fail for empty string") {
val name = ""
assert(IndexName.make(name))(equalTo(Validation.fail(indexNameFailureMessage(name))))
},
test("fail for string '.'") {
val invalidName = "."
assert(IndexName.make(invalidName))(equalTo(Validation.fail(indexNameFailureMessage(invalidName))))
}
},
test("fail for string containing character '*'") {
check(genString(0, 127), genString(0, 128)) { (part1, part2) =>
val invalidName = s"$part1*$part2"
assert(IndexName.make(invalidName))(equalTo(Validation.fail(indexNameFailureMessage(invalidName))))
}
},
test("fail for string containing character ':'") {
check(genString(0, 127), genString(0, 128)) { (part1, part2) =>
val invalidName = s"$part1:$part2"
assert(IndexName.make(invalidName))(equalTo(Validation.fail(indexNameFailureMessage(invalidName))))
}
},
test("fail for empty string") {
val name = ""
assert(IndexName.make(name))(equalTo(Validation.succeed(unsafeWrap(name)(IndexName))))
},
test("fail for string starting with character '-'") {
check(genString(1, 255)) { name =>
val invalidName = s"-$name"
assert(IndexName.make(invalidName))(equalTo(Validation.fail(indexNameFailureMessage(invalidName))))
}
},
test("fail for string '.'") {
val name = "."
assert(IndexName.make(name))(equalTo(Validation.fail(indexNameFailureMessage(name))))
},
test("fail for string longer than 255 bytes") {
check(genString(256, 300)) { name =>
assert(IndexName.make(name))(
equalTo(Validation.fail(indexNameFailureMessage(name)))
)
}
}
},
test("fail for string containing character '*'") {
check(genString(0, 127), genString(0, 128)) { (part1, part2) =>
val invalidName = s"$part1*$part2"
assert(IndexName.make(invalidName))(equalTo(Validation.fail(indexNameFailureMessage(invalidName))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put one empty line between?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this for every test.

}
},
test("fail for string containing character ':'") {
check(genString(0, 127), genString(0, 128)) { (part1, part2) =>
val invalidName = s"$part1:$part2"
assert(IndexName.make(invalidName))(equalTo(Validation.fail(indexNameFailureMessage(invalidName))))
}
},
test("fail for string containing upper letter") {
check(genString(0, 127), genString(0, 128)) { (part1, part2) =>
val invalidName = s"${part1}A$part2"
assert(IndexName.make(invalidName))(equalTo(Validation.fail(indexNameFailureMessage(invalidName))))
}
},
test("fail for string longer than 255 bytes") {
check(genString(256, 300)) { invalidName =>
assert(IndexName.make(invalidName))(
equalTo(Validation.fail(indexNameFailureMessage(invalidName)))
)
}
},
test("fail for string starting with character '-'") {
check(genString(1, 255)) { name =>
val invalidName = s"-$name"
assert(IndexName.make(invalidName))(equalTo(Validation.fail(indexNameFailureMessage(invalidName))))
}
},
test ("succeed for valid string") {
check(genString(1, 255)) { name =>
assert(IndexName.make(name))(equalTo(Validation.succeed(unsafeWrap(name)(IndexName))))
}
},
)
)

private def indexNameFailureMessage(name: String): String =
Expand Down