From 9951e1927a4c6b3268c94d204e73fcebf393c22d Mon Sep 17 00:00:00 2001 From: eevulution <37728480+eevulution@users.noreply.github.com> Date: Fri, 18 Sep 2020 17:25:52 +0300 Subject: [PATCH] Regex feeder (#11) close #5 --- .gitignore | 3 ++- build.sbt | 1 + .../ru/tinkoff/load/example/feeders/Feeders.scala | 3 +++ .../load/example/scenarios/SampleScenario.scala | 1 + project/Dependencies.scala | 4 ++++ .../ru/tinkoff/gatling/feeders/RegexFeeder.scala | 13 +++++++++++++ .../tinkoff/gatling/feeders/RandomFeedersSpec.scala | 10 ++++++++++ 7 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/scala/ru/tinkoff/gatling/feeders/RegexFeeder.scala diff --git a/.gitignore b/.gitignore index a3b7717..77af97a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ *.log *.html /example/target/ -/example/example.iml \ No newline at end of file +/example/example.iml +*.sc diff --git a/build.sbt b/build.sbt index bd1deb4..9a6f089 100644 --- a/build.sbt +++ b/build.sbt @@ -12,6 +12,7 @@ lazy val root = (project in file(".")) libraryDependencies ++= requests, libraryDependencies ++= pureConfig, libraryDependencies ++= scalaTesting, + libraryDependencies ++= generex, scalacOptions := Seq( "-encoding", "UTF-8", diff --git a/example/src/test/scala/ru/tinkoff/load/example/feeders/Feeders.scala b/example/src/test/scala/ru/tinkoff/load/example/feeders/Feeders.scala index 4c84077..4ed691a 100644 --- a/example/src/test/scala/ru/tinkoff/load/example/feeders/Feeders.scala +++ b/example/src/test/scala/ru/tinkoff/load/example/feeders/Feeders.scala @@ -71,4 +71,7 @@ object Feeders { //tranform List to Feeder val list2feeder = List(1, 2, 3).toFeeder("listId").circular + // string sequentially generated from the specified pattern + val regexString = RegexFeeder("regex", "[a-zA-Z0-9]{8}") + } diff --git a/example/src/test/scala/ru/tinkoff/load/example/scenarios/SampleScenario.scala b/example/src/test/scala/ru/tinkoff/load/example/scenarios/SampleScenario.scala index 5e6b7a5..f3db8db 100644 --- a/example/src/test/scala/ru/tinkoff/load/example/scenarios/SampleScenario.scala +++ b/example/src/test/scala/ru/tinkoff/load/example/scenarios/SampleScenario.scala @@ -33,6 +33,7 @@ class SampleScenario { .feed(gluedTogetherFeeder) .feed(list2feeder) .feed(finiteRandomDigitsWithTransform) + .feed(regexString) .exec(getMainPage) } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 85f308a..8a2b159 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -35,6 +35,10 @@ object Dependencies { "org.scalamock" %% "scalamock" % "4.4.0" % "test" ) + lazy val generex: Seq[ModuleID] = Seq( + "com.github.mifmif" % "generex" % "1.0.2" + ) + lazy val scalaTesting: Seq[ModuleID] = scalaCheck ++ scalaTest ++ scalaMock } diff --git a/src/main/scala/ru/tinkoff/gatling/feeders/RegexFeeder.scala b/src/main/scala/ru/tinkoff/gatling/feeders/RegexFeeder.scala new file mode 100644 index 0000000..e895a19 --- /dev/null +++ b/src/main/scala/ru/tinkoff/gatling/feeders/RegexFeeder.scala @@ -0,0 +1,13 @@ +package ru.tinkoff.gatling.feeders + +import io.gatling.core.feeder.Feeder +import com.mifmif.common.regex.Generex + +object RegexFeeder { + + def apply(paramName: String, regex: String): Feeder[String] = { + val generex = new Generex(regex).iterator() + feeder[String](paramName)(generex.next()) + } + +} diff --git a/src/test/scala/ru/tinkoff/gatling/feeders/RandomFeedersSpec.scala b/src/test/scala/ru/tinkoff/gatling/feeders/RandomFeedersSpec.scala index 933d524..730313b 100644 --- a/src/test/scala/ru/tinkoff/gatling/feeders/RandomFeedersSpec.scala +++ b/src/test/scala/ru/tinkoff/gatling/feeders/RandomFeedersSpec.scala @@ -23,6 +23,8 @@ class RandomFeedersSpec extends AnyFlatSpec with Matchers { val uuidPattern = "([a-f0-9]{8}(-[a-f0-9]{4}){4}[a-f0-9]{8})" + val regexPattern = "[a-z0-9]{9}" + it should "create RandomDateFeeder with specified date pattern" in { forAll(rndString, positiveInt, positiveInt) { (paramName, positive, negative) => (positive > negative) ==> @@ -111,6 +113,14 @@ class RandomFeedersSpec extends AnyFlatSpec with Matchers { }.check } + it should "create RegexFeeder with specified regex pattern" in { + forAll(rndString) { (paramName) => + RegexFeeder(paramName, regexPattern) + .take(50) + .forall(r => r(paramName).matches(regexPattern)) + } + } + it should "create SequentialFeeder" in { forAll(rndString, positiveInt, positiveInt) { (paramName, start, step) => val list = SequentialFeeder(paramName, start, step).take(50).toList.flatten