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

Commit

Permalink
Add withPrefix and withSuffix to Pipeline (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhipp authored Apr 12, 2020
1 parent 9313a7e commit 12c6036
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/src/main/scala/dagr/core/tasksystem/Pipeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ abstract class Pipeline(val outputDirectory: Option[Path] = None,

/** Builds an empty task for use within this pipeline. */
def emptyTask: Task = Task.empty

/** Sets the prefix of this pipeline. */
def withPrefix(prefix: String) : this.type = { this.prefix = Some(prefix); this }

/** Sets the suffix of this pipeline. */
def withSuffix(suffix: String) : this.type = { this.suffix = Some(suffix); this }
}
32 changes: 32 additions & 0 deletions core/src/test/scala/dagr/core/tasksystem/PipelineTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,36 @@ class PipelineTest extends UnitSpec {
ts shouldBe List("outerbefore.innerbefore.hello.outerafter.innerafter",
"outerbefore.innerbefore.world.outerafter.innerafter")
}

it should "add prefix when provided after construction" in {
class TestPipeline extends Pipeline {
override def build(): Unit = root ==> named("hello") ==> named("world")
}
val ts = new TestPipeline().withPrefix("new_prefix.").getTasks.map(_.name).toList.sorted
ts shouldBe List("new_prefix.hello", "new_prefix.world")
}

it should "change prefix when provided after construction" in {
class TestPipeline extends Pipeline(prefix=Some("before."), suffix=Some(".after")) {
override def build(): Unit = root ==> named("hello") ==> named("world")
}
val ts = new TestPipeline().withPrefix("new_prefix.").getTasks.map(_.name).toList.sorted
ts shouldBe List("new_prefix.hello.after", "new_prefix.world.after")
}

it should "add suffix when provided after construction" in {
class TestPipeline extends Pipeline {
override def build(): Unit = root ==> named("hello") ==> named("world")
}
val ts = new TestPipeline().withSuffix(".new_suffix").getTasks.map(_.name).toList.sorted
ts shouldBe List("hello.new_suffix", "world.new_suffix")
}

it should "change suffix when provided after construction" in {
class TestPipeline extends Pipeline(prefix=Some("before."), suffix=Some(".after")) {
override def build(): Unit = root ==> named("hello") ==> named("world")
}
val ts = new TestPipeline().withSuffix(".new_suffix").getTasks.map(_.name).toList.sorted
ts shouldBe List("before.hello.new_suffix", "before.world.new_suffix")
}
}

0 comments on commit 12c6036

Please sign in to comment.