Giter Site home page Giter Site logo

Comments (6)

hexdigest avatar hexdigest commented on May 22, 2024 1

Well, Gowrap is not supposed to generate tests. Package name is either "guessed" if the directory of the destination file is empty and doesn't contain any *.go files or loaded from the actual package via standard go/packages package. I don't think it's good idea to introduce special flag for that.

However you can use -v option of the gen command to pass the desired package name to the template (which you also have to modify to use passed variable).

The example can be found in any template in this repo:

{{ $decorator := (or .Vars.DecoratorName (printf "%sWithRateLimit" .Interface.Name)) }}

So if you pass -v DecoratorName=CustomDecoratorName to gowrap then CustomDecoratorName will be uses as a struct name of the decorator.

The only problem here is that the header template that generates package name is hardcoded so maybe I have to introduce some magic variable like PackageName to use approach I described above. WDYT?

from gowrap.

hexdigest avatar hexdigest commented on May 22, 2024 1

@despondency most of the templates now have hardcoded import statements. And gowrap runs goimports and hope that all imports will be resolved correctly. Sometimes it might lead to the cases like you described. You can simply update template and use {{.Import}} template helper rather than import () statement and use latest version of gowrap.

I'll update all common templates to use {{.Import}} soon.

from gowrap.

hexdigest avatar hexdigest commented on May 22, 2024

Hi @Varriount

Thanks for posting this issue.

There are two options to provide a package:

  • Point gowrap to the directory relative to your project, i.e. -p ./pkg/storage
  • Point gowrap to the full import path of the package, i.e. github.com/pkg/errors

Regarding the destination file/package Gowrap should use package name that is used for the destination package.

What option you have troubles with? Can you please provide an example.
Also you mentioned tests are you having troubles with minimock and not gowrap itself?

Can you please provide some code/samples for me to be able to reproduce your issue?

from gowrap.

Varriount avatar Varriount commented on May 22, 2024

I think there might be some confusion here.

I am using gowrap to generate test code for a project I am working on. Since the file gowrap generates is a test file, it resides in the same directory as the implementation code being tested. The test code should have a package name that is the same as the implementation code, but with "_test" at the end, similar to this.

This is because, as far as I can tell, gowrap uses the parent directory name is the name of the package for generated files. There is no way to override this behavior that I can see.

from gowrap.

despondency avatar despondency commented on May 22, 2024

Regarding the packages, we have the following problem : Original file uses google.UUID and when it undergoes templating the wrapped file uses gofrs UUID which is clearly incorrect. Should we explicitly put this in the import statement, or there is a way to make it more generic in which package to import?

from gowrap.

despondency avatar despondency commented on May 22, 2024

Worked like a charm, thank you @hexdigest

from gowrap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.