Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
ADAPT1-1206 | Added v2 test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
aadit-chugh committed Jun 9, 2024
1 parent 0dd909c commit d919d3c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ object TopicMetadataError {
}

case class InvalidContactProvided(contactField: String) extends TopicMetadataError {
override def message: String = s"Field `slackChannel` must start with '#' and be entirely lowercase, without spaces, and less than 80 characters, received '$contactField'!"
override def message: String = s"Field `slackChannel` must start with '#' and must be all lowercase with no spaces and less than 80 characters, received'$contactField'!"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ object Errors {
s"Field `email` not recognized as a valid address, received ${value.compactPrint}."

def invalidSlackChannelProvided(value: JsValue) =
s"Field `slackChannel` field must start with '#' and be entirely lowercase, without spaces, and less than 80 characters, received ${value.compactPrint}."
s"Field `slackChannel` must be all lowercase with no spaces and less than 80 characters, received ${value.compactPrint}."

final case class InvalidSchema(value: JsValue, isKey: Boolean, error: Option[Throwable] = none) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import hydra.avro.registry.SchemaRegistry
import hydra.avro.registry.SchemaRegistry.{SchemaId, SchemaVersion}
import hydra.common.NotificationsTestSuite
import hydra.common.alerting.sender.InternalNotificationSender
import hydra.common.validation.{AdditionalValidation, MetadataAdditionalValidation}
import hydra.common.validation.ValidationError._
import hydra.core.http.CorsSupport
import hydra.core.http.security.entity.AwsConfig
Expand Down Expand Up @@ -223,6 +224,21 @@ final class BootstrapEndpointV2Spec
.unsafeRunSync()
}

"reject a request when slackChannel in contact does not start with # for a new topic" in {
val request = topicMetadataV2Request.copy(
contact = NonEmptyList.of(Slack.create("dev-data-platform").get),
).toJson.compactPrint

testCreateTopicProgram.map {
boostrapEndpoint =>
Put("/v2/topics/dvs.testing", HttpEntity(ContentTypes.`application/json`, request)) ~> Route.seal(
boostrapEndpoint.route) ~> check {
println(responseAs[String])
response.status shouldBe StatusCodes.BadRequest
}
}.unsafeRunSync()
}

"reject a request without a team name" in {
val noTeamName = TopicMetadataV2Request(
Schemas(getTestSchema("key"), getTestSchema("value")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import hydra.kafka.algebras.KafkaClientAlgebra.{ConsumerGroup, Offset, Partition
import hydra.kafka.algebras.MetadataAlgebra.TopicMetadataContainer
import hydra.kafka.algebras.{KafkaAdminAlgebra, KafkaClientAlgebra, MetadataAlgebra, TestMetadataAlgebra}
import hydra.common.validation.AdditionalValidation.allValidations
import hydra.kafka.model.ContactMethod.Email
import hydra.kafka.model.ContactMethod.{Email, Slack}
import hydra.kafka.model.TopicMetadataV2Request.Subject
import hydra.kafka.model._
import hydra.kafka.util.KafkaUtils.TopicDetails
Expand All @@ -29,7 +29,7 @@ import retry.{RetryPolicies, RetryPolicy}
import eu.timepit.refined._
import hydra.common.NotificationsTestSuite
import hydra.common.alerting.sender.InternalNotificationSender
import hydra.common.validation.AdditionalValidation
import hydra.common.validation.{AdditionalValidation, MetadataAdditionalValidation}
import hydra.common.validation.ValidationError.ValidationCombinedErrors
import hydra.kafka.IOSuite
import hydra.kafka.algebras.RetryableFs2Stream.RetryPolicy.Once
Expand Down Expand Up @@ -2410,12 +2410,31 @@ class CreateTopicProgramSpec extends AsyncFreeSpec with Matchers with IOSuite {
testSuccess(request, previousTopics = topics, createReplacementAndPreviousTopics = true)
}

"accept request if the slackChannel in the contact doesn't start with '#' when updating for an old topic." in {
val slackChannel = "dev-data-platform"
val updatedRequest = topicMetadataRequest.copy(contact = NonEmptyList.of(Slack.create(slackChannel).get), additionalValidations = AdditionalValidation.allValidations.filterNot(_ == MetadataAdditionalValidation.contactValidation))
testSuccess(updatedRequest, additionalValidations = AdditionalValidation.allValidations.filterNot(_ == MetadataAdditionalValidation.contactValidation))
}

"throw error if the slackChannel in the contact doesn't start with '#' when updating for a new topic." in {
val slackChannel = "dev-data-platform"
val updatedRequest = topicMetadataRequest.copy(contact = NonEmptyList.of(Slack.create(slackChannel).get))
val result = for {
ts <- initTestServices()
_ <- ts.program.createTopic(subject, topicMetadataRequest, topicDetails)
_ <- ts.program.createTopic(subject, updatedRequest, topicDetails)
} yield ()

result.attempt.map(_ shouldBe TopicMetadataError.InvalidContactProvided(slackChannel).asLeft)
}

def testSuccess(request: TopicMetadataV2Request,
deprecated: Boolean = false,
deprecatedDate: Option[Instant] = None,
replacementTopics: Option[List[String]] = None,
previousTopics: Option[List[String]] = None,
createReplacementAndPreviousTopics: Boolean = false) = {
createReplacementAndPreviousTopics: Boolean = false,
additionalValidations: Option[List[AdditionalValidation]] = AdditionalValidation.allValidations) = {
for {
publishTo <- Ref[IO].of(Map.empty[String, (GenericRecord, Option[GenericRecord], Option[Headers])])
consumeFrom <- Ref[IO].of(Map.empty[Subject, TopicMetadataContainer])
Expand All @@ -2437,7 +2456,7 @@ class CreateTopicProgramSpec extends AsyncFreeSpec with Matchers with IOSuite {
deprecatedDate = deprecatedDate,
replacementTopics = replacementTopics,
previousTopics = previousTopics,
additionalValidations = AdditionalValidation.allValidations
additionalValidations = additionalValidations
)))
} yield {
published shouldBe Map(metadataTopic -> (expectedTopicMetadata._1, expectedTopicMetadata._2, None))
Expand Down

0 comments on commit d919d3c

Please sign in to comment.