goexample | Various examples of tests I do on a daily basis | Learning library
kandi X-RAY | goexample Summary
kandi X-RAY | goexample Summary
Various examples of tests I do on a daily basis before implementing golang. ** NOTE: ** The examples below are for educational use only, to practice and test various possibilities of golang implementations. Before developing projects in golang I do several unit tests and I am making my tests and examples available to the community, and maybe I can help you. It was one of the ways I found to know a little more language. I hope they help you.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Run the DynamoDB command .
- finder is the main function .
- content shows the entire table .
- handlerExec executes the request .
- GetStringJson retrieves a string from BoltDB
- prepare is the main function
- goApiUpdate is used to update an api update
- goPgUpdate executes a query
- goApiHello handles the hello request
- Auth is used to show the authentication header
goexample Key Features
goexample Examples and Code Snippets
Community Discussions
Trending Discussions on goexample
QUESTION
My post has 2 question
I'm essentially trying to understand how to use gomock with gingko
GOPATH
/Users/Ratatouille/Desktop/test/goExample
The following project is located at
/Users/Ratatouille/Desktop/test/goExample/square
which has following project structure
...ANSWER
Answered 2017-Jul-03 at 11:12Your project structure isn't the one Go expects.
area_test/
are not the tests for area
. I'm going to guess you ran go test ./area_test
. That tells Go that ./area_test
is a project. It tried to compile area_mock.go
and tried to use area_mock_test.go
and area_suite_test.go
as its tests. The error you got is Go's awkward way of telling you that it did not expect to find a package named *_test
in a project file.
area.go
is also a problem. You have it using package main
, but then try to test with package area_test
. They don't match and Go won't like it. A package directory contains one package. Its tests must use either that package or thatpackage_test
. This enforces that a package directory does one thing. Its either a library to import, or its a program to run. Not both.
Also the project directory is called square
, but the package is area
. It's ok to have files that don't match the project name, and its fine to have multiple files in one package, but using a package than the project directory name is not good practice.
There's another problem. Go expects source files to be in $GOPATH/src
. You have them directly in $GOPATH
. Import statements won't find them.
Go's project structure can take a bit of getting used to, and it has very firm ideas about how projects and packages are to be structured (Go has very firm ideas about how code is to be written, and how it isn't). Don't fight it. Do yourself a favor and use the default GOPATH
of ~/go
and put your code in ~/go/src/
.
You'd write the square library like so.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install goexample
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page