I'm trying to include godog in a go project in order to test some APIs. This is the structure
- Project Folder
- ...
- ...
- src
- cmd
- features
- ready.feature
- main.go
- main_test.go
- features
- cmd
The webserver starts in the main() function contained in a file named main.go under the cmd folder. So I have added under the cmd folder a new features folder with a ready.feature file:
Feature: get ready
In order to know if microservice is ready
As an API user
I need to be able to check the ready
Scenario: should get ready
When I send "GET" request to "/ready"
Then the response code should be 200
And the response should match json:
"""
{
service is ready
}
"""
Now, after the execution of this command:
godog run ready.feature
I get :
func iSendRequestTo(arg1, arg2 string) error {
return godog.ErrPending
}
func theResponseCodeShouldBe(arg1 int) error {
return godog.ErrPending
}
func theResponseShouldMatchJson(arg1 *godog.DocString) error {
return godog.ErrPending
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^I send "([^"]*)" request to "([^"]*)"$`, iSendRequestTo)
ctx.Step(`^the response code should be (\d+)$`, theResponseCodeShouldBe)
ctx.Step(`^the response should match json:$`, theResponseShouldMatchJson)
}
So I've created the main_test.go file under the cmd folder with the content suggested by godog and tried to run godog (in order to run the test) with the command "godog run" but I get every time (and yes, I've reworked the main_test.go file) this error:
failed to compile testmain package: exit status 2 - output: /tmp/go-build2631598204/b001/_testmain.go:5:8: could not import project/src/cmd (open : no such file or directory)
Could you help me, please ?