NorfairKing / sydtest

A modern testing framework for Haskell with good defaults and advanced testing features.
113 stars 25 forks source link

Add servantSpec functions that allow passing a context #44

Closed L7R7 closed 2 years ago

L7R7 commented 2 years ago

This addresses #42. I tried to be as minimal as possible in the test (maybe it's even a bit too simplistic, but it's enough to show that it works)

Closes #42

L7R7 commented 2 years ago

It's a draft for now because I'm sure I'm not done yet. I'm struggling with the nix setup on my machine so I can't get proper feedback locallly yet

NorfairKing commented 2 years ago

Looks pretty good!

L7R7 commented 2 years ago

Ok, so I am actually quite happy with what is there. I'd like to add a test that makes sure that access is forbidden when using wrong credentials but I'm stuck because I can't figure out how to properly catch the error servant-client will throw in this case.

I also thought about reducing code duplication a bit by delegatng clientEnvSetupFunc to clientEnvSetupFuncWithContext using EmptyContext, but I think it's good enough the way it is now. If you want that, I can add it.

L7R7 commented 2 years ago

Oh, let me know if you think it's tested well enough already. I'd remove clientGetWrongCredentials then

NorfairKing commented 2 years ago

I can't figure out how to properly catch the error servant-client will throw in this case.

You use runClientM manually:

it "foobar" $ \clientEnv -> do
  errOrResult <- runClientM functionHere clientEnv
L7R7 commented 2 years ago

Thanks for the hint! I'll have to figure out how that works, but I can say it's nice to use :+1:

I'm happy with the changes now. Let me know what you think

NorfairKing commented 2 years ago

@L7R7 Before we continue, just to be sure: are you aware of and in agreement with the license?

L7R7 commented 2 years ago

Yes, I am and I'm fine with it

NorfairKing commented 2 years ago

Merged and released, Great thanks!