-
Couldn't load subscription status.
- Fork 1.4k
Add "Setter" / "Update" Methods to Mock Services #1252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi @adamgfraser. I'm working on something else, would you be willing to include TestClock as well in this PR? Thanks. |
|
@vasilmkd Sure, happy to take it! |
|
I updated this to include |
| } yield input | ||
| } | ||
|
|
||
| def feedLine(line: String): UIO[Unit] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update the signature slightly, for added user-convenience?
def feedLines(lines: String*): UIO[Unit] =| def feedLine(line: String): UIO[Unit] = | ||
| ref.update(data => data.copy(input = line :: data.input)).unit | ||
|
|
||
| val output: UIO[Vector[String]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good. Probably good to add a clearOutput, too, and maybe clearInput.
|
|
||
| def shuffle[A](list: List[A]): UIO[List[A]] = Random.shuffleWith(nextInt, list) | ||
|
|
||
| def feedInt(int: Int): UIO[Unit] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto on these, I'd update to feedInts(ints: Int*) for all of them, and add clear methods as well.
| def putEnv(name: String, value: String): UIO[Unit] = | ||
| ref.update(data => data.copy(envs = data.envs.updated(name, value))).unit | ||
|
|
||
| def putProperty(name: String, value: String): UIO[Unit] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, and probably useful to make a clearEnv / clearProperty, as well.
| object TestRandom { | ||
| val DefaultData: Data = Data() | ||
|
|
||
| def apply(data: Data): UIO[TestRandom] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are super handy! I would call them make, though, instead of apply, because they build it inside an effect, rather than return it directly.
| import zio.test.mock.TestRandom.Data | ||
|
|
||
| final case class TestRandom(ref: Ref[TestRandom.Data]) extends Random.Service[Any] { | ||
| final case class TestRandom(private val ref: Ref[TestRandom.Data]) extends Random.Service[Any] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not make this private. Let's just call them, randomState, clockState, systemState, consoleState, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! A few quick changes and it will be good to merge.
|
@adamgfraser Any interest in taking this one too? 😄 |
|
@jdegoes Yes I will take it! |
|
@adamgfraser Thank you!!! 🙏 |
|
@jdegoes Thanks for your feedback! These should all be addressed now. |
|
@adamgfraser Great work, thank you for this! |
* Add "setter" / "update" methods to mock services * include TestClock * resolve review comments
Adds "setter" / "update" methods to
TestConsole,TestSystem, andTestRandommock services and hidesRefimplementation as proposed in #1240.