mockery
mockery copied to clipboard
Mockery fails when the envvar 'MOCKERY_VERSION' is set to a value other than 'true' or 'false'
Hi, maybe this will be disregarded as an issue, you might want to close it. But I spent a good part of my day trying to solve it, so I am posting here in case it helps someone else.
Basically I was trying to run mockery inside a container. My Dockerfile looked like this:
FROM golang:1.15
# Install mockery
ENV MOCKERY_VERSION=2.5.1
RUN cd /opt && \
curl -L https://github.com/vektra/mockery/releases/download/v${MOCKERY_VERSION}/mockery_${MOCKERY_VERSION}_Linux_x86_64.tar.gz -o mockery.tar.gz && \
mkdir mockery && \
tar -xf mockery.tar.gz -C mockery && \
mv mockery/mockery /usr/local/bin/
And everytime I tried to run mockery inside that container I would get this error:
root@7e0c7fa4ad06:/go# mockery showconfig
Error: failed to unmarshal config: 1 error(s) decoding:
* cannot parse 'Version' as bool: strconv.ParseBool: parsing "2.5.1": invalid syntax
Usage:
mockery showconfig [flags]
So I spent some time to find out that mockery (with help from viper) automatically picks up environmental variables that start with MOCKERY_
and that was messing up the parsing of the config.
Not sure how one would solve it. But I don't think it's useful to have an envvar to print the version or not. Specially when it will not make any difference when running other commands. Because version will not be printed either way when executing commands.
It might not be the right solution (or a good long term solution) but changing the line ENV MOCKERY_VERSION=2.5.1
to ARG MOCKERY_VERSION=2.5.1
will likely fix your problem
This seems like an unintended effect. Viper seems to be automatically mapping that env variable to the Version
config. Can you just rename it to something else? Using ARG
like @corsc recommended might also work.
Thank you for your comments and suggestions.
Yes, I ended up renaming it to MOCKERY_INSTALL_VERSION
. I just wanted to raise attention to this behaviour as someone else might have the sam issue.
Thank you for this - just got bitten by the same error and this has saved me a lot of time...
Didn't fix mine, FWIW. Renaming the var entirely did though!
I've added this to the FAQ docs here: https://vektra.github.io/mockery/notes/#mockery-fails-to-run-when-mockery_version-environment-variable-is-set
Closing this issue as we can't actually fix this, and the solution is posted above.