Skip to content
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

RedisClient.pipeline not possible to mock for testing #217

Open
chris-zen opened this issue Aug 29, 2018 · 3 comments
Open

RedisClient.pipeline not possible to mock for testing #217

chris-zen opened this issue Aug 29, 2018 · 3 comments

Comments

@chris-zen
Copy link

chris-zen commented Aug 29, 2018

I have a function like:

def write(redisClient: RedisClient) = {
  redisClient.pipeline { pipe =>
    pipe.set("k1", "v1")
    pipe.set("k2", "v2")
  }
}

Given that the type of pipe is RedisClient.this.PipelineClient and PipelineClient is an Inner Class, it is not possible to write something like this in a test (the code doesn't compile because it is not possible to import PipelineClient):

val redisClient: RedisClient = mock[RedisClient]
val pipelineClient: PipelineClient = mock[PipelineClient]
when(redisClient.pipeline(any())).thenAnswer((invocation: InvocationOnMock) => {
  invocation.getArgument[PipelineClient => Any](0).apply(pipelineClient)
})

I see that PipelineClient is implemented as an Inner Class, but used as an Static Class, as it receives a reference to its parent, and all the accesses to it are done through the reference.

I am wondering if it could be possible to make PipelineClient an static class so pipelining can be easily mocked. I could prepare the PR if you wish.

@mjuanes
Copy link

mjuanes commented Jan 17, 2020

Same issue here, I think I'll choose another library.

@solyd
Copy link

solyd commented Jan 29, 2020

this works for me (am able to refer to PipelineClient as a type):

  val tmp = mock[RedisClient]
  def pipeline(f: tmp.PipelineClient => Any): Option[List[Any]] = {
    // ...
  }

@noahlz
Copy link

noahlz commented Oct 20, 2021

I also encountered this... PipelineClient is documented but not accessible. Not sure I understand the why you wouldn't at least expose this as a trait? Unless we should just be using RedisCommand?

https://www.javadoc.io/doc/net.debasishg/redisclient_2.12/3.20/com/redis/RedisClient.html#PipelineClientextendsRedisCommandwithPubOperations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants