mockery icon indicating copy to clipboard operation
mockery copied to clipboard

Mockery fails when the envvar 'MOCKERY_VERSION' is set to a value other than 'true' or 'false'

Open vitorarins opened this issue 3 years ago • 5 comments

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.

vitorarins avatar Jun 24 '21 15:06 vitorarins

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

corsc avatar Jun 28 '21 01:06 corsc

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.

LandonTClipp avatar Jun 28 '21 17:06 LandonTClipp

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.

vitorarins avatar Jul 03 '21 17:07 vitorarins

Thank you for this - just got bitten by the same error and this has saved me a lot of time...

eccles avatar Oct 26 '21 09:10 eccles

Didn't fix mine, FWIW. Renaming the var entirely did though!

jcburley avatar Dec 08 '21 23:12 jcburley

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.

LandonTClipp avatar Jun 15 '23 15:06 LandonTClipp