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

Question: Possibility to use different approval files depending on OS platform #248

Open
DGuhr opened this issue Mar 24, 2022 · 3 comments

Comments

@DGuhr
Copy link

DGuhr commented Mar 24, 2022

Hey :)

I hope you could help me with the following question: Is it possible to point the library to different approval files depending on the operating system? If so, how?

context:
We're using approvalTests to check CLI outputs in our new keycloak testsuite for the quarkus cli. See here [1] [2] for an approvalTest, and here for the folder containing the approvals.

Everything is fine as long as we're on a unix system, but we're also cross-platform, so windows is a thing and there we use a kc.bat entrypoint instead of kc.sh on unix, and this is included in the approvals. So now I am searching a way to tell the tests "if on windows, use this folder containing the windows approvals with kc.bat inside, and if on unix (macos/linux) use that folder with the corresponding approvals inside." - The detection of the OS is not the problem, but for the "point to different approval files based on that condition" part i can't find something, so hope you could help me :)

Thanks in advance!

@LarsEckart
Copy link
Contributor

hello, first of all, thats a really cool use-case of using approval tests.

I've 2 thoughts about this:

  1. you could split it into 2 tests and use conditional annotations from junit5

  2. If you wrap the call to Approvals.verify the following way, I think it will add the OS into the approved file name, like for example here: src/test/java/org/approvaltests/machine_specific_tests/ApprovalsTest.testApproveComponent.Mac_OS_X.approved.png.

    try (NamedEnvironment env = NamerFactory.asOsSpecificTest())
    {
      Approvals.verify(getOutput());
    }

@DGuhr
Copy link
Author

DGuhr commented Mar 24, 2022

thanks for the fast response! You are right, conditionals may be helpful. I think 2nd approach is not usable as is, because it's more coarse grained for us, its either windows or "all others", as e.g. linux and osx behave the same when it comes to sh files. But will look into the NamerFactory later on :)

@DGuhr
Copy link
Author

DGuhr commented Mar 24, 2022

just created a little approvaltest extension to have a KcNamerFactory that has a WindowsOrUnixOsEnvironmentLabeller inside that returns either "windows" when os.name (to lower) contains "windows", or "unix" otherwise. Works for me (on macos) at least , so thanks again.

Have to give it a few tries and spin up the windows vm later on to see if it also works there, but if it works and if you want i can contribute back for sure. :)

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

2 participants