Skip to content

Commit

Permalink
Merge pull request #212 from hmrc/BDOG-3289-1
Browse files Browse the repository at this point in the history
BDOG-3289 refactor TestType parsing
  • Loading branch information
jordanrowe authored Nov 12, 2024
2 parents 2c6597d + 8c2280f commit ae1e377
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ case class GhRepository(
.repoType
.getOrElse(repoTypeHeuristics.inferredRepoType)

val testType: Option[TestType] =
manifestDetails
.testType
.orElse(ManifestDetails.deriveTestType(name))

val prototypeName: Option[String] =
Option.when(repoType == RepoType.Prototype)(
manifestDetails
Expand All @@ -395,7 +400,7 @@ case class GhRepository(
isPrivate = isPrivate,
repoType = repoType,
serviceType = manifestDetails.serviceType,
testType = manifestDetails.testType,
testType = testType,
tags = manifestDetails.tags,
digitalServiceName = manifestDetails.digitalServiceName,
owningTeams = manifestDetails.owningTeams.sorted,
Expand Down Expand Up @@ -436,7 +441,7 @@ object GhRepository:
.split("-").map(_.capitalize).mkString("-")
.trim

private def deriveTestType(repoName: String): Option[TestType] =
def deriveTestType(repoName: String): Option[TestType] =
repoName match
case name if "(?i)(performance|perf)(-test(s)?)".r.findFirstIn(name).isDefined => Some(TestType.Performance)
case name if "(?i)(acceptance|ui|journey|api|contract)(-test(s)?)".r.findFirstIn(name).isDefined => Some(TestType.Acceptance)
Expand All @@ -448,20 +453,10 @@ object GhRepository:
logger.warn(s"repository.yaml for $repoName is not valid YAML and could not be parsed. Parsing Exception: ${exception.getMessage}")
None
case Success(config) =>
val repoType = Parser[RepoType].parse(config.get[String]("type").getOrElse("")).toOption
val serviceType =
if repoType.contains(RepoType.Service) then
Parser[ServiceType].parse(config.get[String]("service-type").getOrElse("")).toOption
else None
val testType =
if repoType.contains(RepoType.Test) then
Parser[TestType].parse(config.get[String]("test-type").getOrElse("")).toOption
.orElse(deriveTestType(repoName))
else None
val manifestDetails = ManifestDetails(
repoType = repoType
, serviceType = serviceType
, testType = testType
repoType = Parser[RepoType].parse(config.get[String]("type").getOrElse("")).toOption
, serviceType = Parser[ServiceType].parse(config.get[String]("service-type").getOrElse("")).toOption
, testType = Parser[TestType].parse(config.get[String]("test-type").getOrElse("")).toOption
, tags = config.getArray("tags").map(_.flatMap(str => Parser[Tag].parse(str).toOption).toSet)
, digitalServiceName = config.get[String]("digital-service").map(formatDigitalServiceName)
, description = config.get[String]("description")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,42 +209,30 @@ class ManifestDetailsTest extends AnyWordSpecLike with Matchers:
tt shouldBe TestType.Performance

"derive test type from repo name" in:
val manifest =
"""
|type: test
|""".stripMargin

val performance = ManifestDetails.parse("example-performance-tests", manifest)
performance.fold(fail("Unable to parse yaml")): data =>
data.testType.fold(fail("Unable to parse test-type from performance-tests in repo name")): tt =>
ManifestDetails.deriveTestType("example-performance-tests")
.fold(fail("Unable to parse test-type from performance-tests in repo name")): tt =>
tt shouldBe TestType.Performance

val perf = ManifestDetails.parse("example-perf-tests" , manifest)
perf.fold(fail("Unable to parse yaml")): data =>
data.testType.fold(fail("Unable to parse test-type from perf-tests in repo name")): tt =>
ManifestDetails.deriveTestType("example-perf-tests")
.fold(fail("Unable to parse test-type from perf-tests in repo name")): tt =>
tt shouldBe TestType.Performance

val acceptance = ManifestDetails.parse("example-acceptance-tests" , manifest)
acceptance.fold(fail("Unable to parse yaml")): data =>
data.testType.fold(fail("Unable to parse test-type from acceptance-tests in repo name")): tt =>
ManifestDetails.deriveTestType("example-acceptance-tests")
.fold(fail("Unable to parse test-type from acceptance-tests in repo name")): tt =>
tt shouldBe TestType.Acceptance

val ui = ManifestDetails.parse("example-ui-tests" , manifest)
ui.fold(fail("Unable to parse yaml")): data =>
data.testType.fold(fail("Unable to parse test-type from ui-tests in repo name")): tt =>
ManifestDetails.deriveTestType("example-ui-tests")
.fold(fail("Unable to parse test-type from ui-tests in repo name")): tt =>
tt shouldBe TestType.Acceptance

val journey = ManifestDetails.parse("example-journey-tests" , manifest)
journey.fold(fail("Unable to parse yaml")): data =>
data.testType.fold(fail("Unable to parse test-type from journey-tests in repo name")): tt =>
ManifestDetails.deriveTestType("example-journey-tests")
.fold(fail("Unable to parse test-type from journey-tests in repo name")): tt =>
tt shouldBe TestType.Acceptance

val api = ManifestDetails.parse("example-api-tests" , manifest)
api.fold(fail("Unable to parse yaml")): data =>
data.testType.fold(fail("Unable to parse test-type from api-tests in repo name")): tt =>
ManifestDetails.deriveTestType("example-api-tests")
.fold(fail("Unable to parse test-type from api-tests in repo name")): tt =>
tt shouldBe TestType.Acceptance

val contract = ManifestDetails.parse("example-contract-tests" , manifest)
contract.fold(fail("Unable to parse yaml")): data =>
data.testType.fold(fail("Unable to parse test-type from contract-tests in repo name")): tt =>
ManifestDetails.deriveTestType("example-contract-tests")
.fold(fail("Unable to parse test-type from contract-tests in repo name")): tt =>
tt shouldBe TestType.Acceptance

0 comments on commit ae1e377

Please sign in to comment.