On Tue, Dec 15, 2015 at 2:38 PM, JM <je...@magentatech.com> wrote:
> Any idea why I get this error if i have my test in the same package name as
> the Entity class? If i add _test to the end of the entity package on my test
> file, it works.
>
>
> C:\GoPath\src\github.com\xyz\api\domain\entity>go test
> # github.com/xyz/api/domain/entity
> import cycle not allowed in test
> package github.com/xyz/api/domain/entity (test)
> imports github.com/xyz/api/domain/entity
>
> FAIL github.com/xyz/api/domain/entity [setup failed]
If you put your test in package entity, then it really is in package
entity. It should not import entity itself--that is a package
importing itself, which is a (simple) cycle.
If you put your test in package entity_test, then it is in a different
package, and can import what it likes.
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/3hPEtCNm3XA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Oh, one thing I didn't make it clear is that I was planning to convert my test cases into (testable) examples. Thus those test cases will serve two purposes, testing my code while documenting how the lib can/should be used at the same time.Removing the package name from in front of the struct or members/member-functions(e.g., https://github.com/suntong/easygen/pull/2/files#diff-0, thank you bruston BTW) would be the last resort I want to take because of the above goal, as users seeing the example have to put them back before they can use them.So, I guess that I can't have both right? I.e., I can't leave my test in the same package if I want to achieve above right? Guess I have to split my test into a separated package then. That's the only option I have now, right?
I guess the next question is, why the same test command `go test -v ./...`, works for my locally, but not works on codeship.com? It the exactly same command. I don't understand. If I can fix codeship build, then I don't need to the split I guess.
I guess the next question is, why the same test command `go test -v ./...`, works for my locally, but not works on codeship.com? It the exactly same command. I don't understand. If I can fix codeship build, then I don't need to the split I guess.Can you please provide some details about what you tried to set on codeship, what you expected to happen, and what happened instead.
In your first example, your code is not under GOPATH.
Oh, one thing I didn't make it clear is that I was planning to convert my test cases into (testable) examples. Thus those test cases will serve two purposes, testing my code while documenting how the lib can/should be used at the same time.Removing the package name from in front of the struct or members/member-functions(e.g., https://github.com/suntong/easygen/pull/2/files#diff-0, thank you bruston BTW) would be the last resort I want to take because of the above goal, as users seeing the example have to put them back before they can use them.So, I guess that I can't have both right? I.e., I can't leave my test in the same package if I want to achieve above right? Guess I have to split my test into a separated package then. That's the only option I have now, right?