petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
252 stars 28 forks source link

v1.13 go mod incompatible #91

Closed alexbeltran closed 4 years ago

alexbeltran commented 4 years ago

When running:

go mod tidy

The following is outputted from the generated mock package.

go: finding github.com/petergtz/pegomock/matchers latest
github.com/...../mock/mCommand imports
        github.com/petergtz/pegomock tested by
        github.com/petergtz/pegomock.test imports
        github.com/petergtz/pegomock/matchers: module github.com/petergtz/pegomock@latest (v2.5.0+incompatible) found, but does not contain package github.com/petergtz/pegomock/matchers

Not clear why it is looking for a matchers library since it isn't in the generated mock package. See imports:

package mCommand

import (
    pegomock "github.com/petergtz/pegomock"
    command "....command"
    "reflect"
    "time"
)
petergtz commented 4 years ago

Hi @alexbeltran,

thank you very much for reporting this. I don't have time to look into this right now, but will see if I can address it in the coming days. If you could provide me with some example file/directory structure, that would help to speed things up quite a bit.

Thank you, Peter

petergtz commented 4 years ago

@alexbeltran OK, finally had the time to look into this. So here's the issue:

go mod tidy adds your dependencies' test dependencies to your module. (See https://github.com/golang/go/issues/29323, https://github.com/golang/go/issues/27633, https://github.com/golang/go/issues/26626 and https://github.com/golang/go/issues/26955)

This causes an issue here, because pegomock's own tests depend on a package (i.e. the matchers package) which itself gets generated as part of the test suite.

I'm not sure I'm excited about the fact go mod tidy adds test dependencies, because I don't see the use case of running your dependencies' test suites. Any integration test suite requires a certain environment to run anyway, so it's unrealistic to run them.

I guess we could do the following: commit the matchers package to git and therefore satisfy go mod tidy. They get temporarily removed by scripts/run_tests.sh anyway to make sure they get generated properly before the tests run.

Do you think that would solve your problem?

petergtz commented 4 years ago

@alexbeltran I just went ahead an made the change on develop. Could you try and see if that solves your problem?

alexbeltran commented 4 years ago

Thanks for investigating this so qiuckly. Sorry I didn't get back to you immediately.

The develop branch works for me which is great. :) I also agree, it is strange that go mod tidy would add test dependencies. >.> Including them does fix tidy though.

petergtz commented 4 years ago

Okay cool. Will make a release later this week.