dongyishen5796 2017-02-15 07:06
浏览 36

如何正确模拟导入的库?

I have an import:

import {
    "github.com/aws/aws-sdk-go/service/route53"
}

Which I then use to work with host zones in AWS Route 53. I see that the code I created works properly now with the current setup.

To simplify development process, I want to create a mock of the library methods I use while developing.

I have a key in config, like this env="development" or env="production".

My plan is to add my own object that is route53 with the needed methods and import it if the env is development.

How do I do it better? Does golang support conditional importing, like this:

if (env=="development") {
    import "./route53-mock"
} else {
    "github.com/aws/aws-sdk-go/service/route53"
}
  • 写回答

3条回答 默认 最新

  • doudian7996 2017-02-15 07:36
    关注

    "Does golang support conditional importing [?]". Answer: No. Just take a look at the language spec.

    "How do I do it better?" Answer: Route calls to route53 through your own package which switches between mock and real route53 depending on your environment/build -tags/cmdlineargs/whatever.

    评论

报告相同问题?