Skip to content

Commit

Permalink
Regex feeder (#11)
Browse files Browse the repository at this point in the history
close #5
  • Loading branch information
eevulution authored Sep 18, 2020
1 parent 526189c commit 9951e19
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
*.log
*.html
/example/target/
/example/example.iml
/example/example.iml
*.sc
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ lazy val root = (project in file("."))
libraryDependencies ++= requests,
libraryDependencies ++= pureConfig,
libraryDependencies ++= scalaTesting,
libraryDependencies ++= generex,
scalacOptions := Seq(
"-encoding",
"UTF-8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SampleScenario {
.feed(gluedTogetherFeeder)
.feed(list2feeder)
.feed(finiteRandomDigitsWithTransform)
.feed(regexString)
.exec(getMainPage)

}
4 changes: 4 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
13 changes: 13 additions & 0 deletions src/main/scala/ru/tinkoff/gatling/feeders/RegexFeeder.scala
Original file line number Diff line number Diff line change
@@ -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())
}

}
10 changes: 10 additions & 0 deletions src/test/scala/ru/tinkoff/gatling/feeders/RandomFeedersSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) ==>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9951e19

Please sign in to comment.