-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an issue where if the first resource is not a script, the resourc…
…e is silently dropped (#670) * Fix an issue where if the first resource is not a script, the resource is silently dropped * Fill in PR # * Update src/main/scala/io/viash/functionality/Functionality.scala Co-authored-by: Robrecht Cannoodt <rcannood@gmail.com> * Add other edge case in test --------- Co-authored-by: Robrecht Cannoodt <rcannood@gmail.com>
- Loading branch information
Showing
3 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/test/scala/io/viash/functionality/MainScriptTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package io.viash.functionality | ||
|
||
import org.scalatest.funsuite.AnyFunSuite | ||
import io.viash.helpers.Logger | ||
import io.viash.functionality.resources.{BashScript, PlainFile} | ||
|
||
class MainScriptTest extends AnyFunSuite { | ||
Logger.UseColorOverride.value = Some(false) | ||
|
||
test("Single script") { | ||
val resources = List(BashScript(path = Some("foo.sh"))) | ||
val fun = Functionality("fun", resources = resources) | ||
|
||
val mainScript = fun.mainScript | ||
val additionalResources = fun.additionalResources | ||
|
||
assert(mainScript.isDefined) | ||
assert(mainScript.get.path == Some("foo.sh")) | ||
assert(additionalResources.isEmpty) | ||
} | ||
|
||
test("Multiple scripts") { | ||
val resources = List( | ||
BashScript(path = Some("foo.sh")), | ||
BashScript(path = Some("bar.sh")), | ||
BashScript(path = Some("baz.sh")), | ||
) | ||
val fun = Functionality("fun", resources = resources) | ||
|
||
val mainScript = fun.mainScript | ||
val additionalResources = fun.additionalResources | ||
|
||
assert(mainScript.isDefined) | ||
assert(mainScript.get.path == Some("foo.sh")) | ||
assert(additionalResources.length == 2) | ||
} | ||
|
||
test("Single text file") { | ||
val resources = List(PlainFile(path = Some("foo.txt"))) | ||
val fun = Functionality("fun", resources = resources) | ||
|
||
val mainScript = fun.mainScript | ||
val additionalResources = fun.additionalResources | ||
|
||
assert(mainScript.isEmpty) | ||
assert(additionalResources.length == 1) | ||
assert(additionalResources.head.path == Some("foo.txt")) | ||
} | ||
|
||
test("Multiple text files") { | ||
val resources = List( | ||
PlainFile(path = Some("foo.txt")), | ||
PlainFile(path = Some("bar.txt")), | ||
PlainFile(path = Some("baz.txt")), | ||
) | ||
val fun = Functionality("fun", resources = resources) | ||
|
||
val mainScript = fun.mainScript | ||
val additionalResources = fun.additionalResources | ||
|
||
assert(mainScript.isEmpty) | ||
assert(additionalResources.length == 3) | ||
} | ||
|
||
test("Mixed Script and text files, first is script") { | ||
val resources = List( | ||
BashScript(path = Some("foo.sh")), | ||
PlainFile(path = Some("bar.txt")), | ||
BashScript(path = Some("baz.sh")), | ||
) | ||
|
||
val fun = Functionality("fun", resources = resources) | ||
|
||
val mainScript = fun.mainScript | ||
val additionalResources = fun.additionalResources | ||
|
||
assert(mainScript.isDefined) | ||
assert(mainScript.get.path == Some("foo.sh")) | ||
assert(additionalResources.length == 2) | ||
} | ||
|
||
test("Mixed Script and text files, first is text file") { | ||
val resources = List( | ||
PlainFile(path = Some("foo.txt")), | ||
BashScript(path = Some("bar.sh")), | ||
PlainFile(path = Some("baz.txt")), | ||
) | ||
|
||
val fun = Functionality("fun", resources = resources) | ||
|
||
val mainScript = fun.mainScript | ||
val additionalResources = fun.additionalResources | ||
|
||
assert(mainScript.isEmpty) | ||
assert(additionalResources.length == 3) | ||
} | ||
|
||
test("No resources") { | ||
val resources = List.empty | ||
val fun = Functionality("fun", resources = resources) | ||
|
||
val mainScript = fun.mainScript | ||
val additionalResources = fun.additionalResources | ||
|
||
assert(mainScript.isEmpty) | ||
assert(additionalResources.isEmpty) | ||
} | ||
} |