Got error when running "Use 'mock' flag to tell package rest that you would like to use mockups."
Closed this issue · 10 comments
The Code:
package rest
import (
"github.com/mercadolibre/golang-restclient/rest"
"github.com/stretchr/testify/assert"
"net/http"
"os"
"testing"
)
func TestMain(m *testing.M) {
rest.StartMockupServer()
os.Exit(m.Run())
}
func TestLoginUserTimeoutFromApi(t *testing.T) {
rest.FlushMockups()
rest.AddMockups(&rest.Mock{
HTTPMethod: http.MethodPost,
URL: "http://localhost:8282/users/login",
ReqBody: `{"email":"firman@gmail.com","password":"firman123"}`,
RespHTTPCode: -1,
RespBody: `{}`,
})
repo := usersRepository{}
user, err := repo.LoginUser("email@gmail.com", "the-password")
assert.Nil(t, user)
assert.NotNil(t, err)
assert.EqualValues(t, http.StatusInternalServerError, err.Status)
assert.EqualValues(t, "invalid restclient response when trying to login user", err.Message)
}
The error:
Usage of .........
flag provided but not defined: -test.v
-mock
Use 'mock' flag to tell package rest that you would like to use mockups.
Process finished with exit code 1
Tests where working with go v1.12 but with v1.13 and v1.14 getting the same error.
Any update here?
Hi,
i can see it's closed. Does it mean there's something on the roadmap or it's already fixed for gov1.14 ?
Best.
@BigBoulard There's a Pull request to fix this. here, Alternatively, you can modify the same files as per the PR locally as you're waiting for the PR to be merged
Hi I'm also experiencing the same issue. I just downloaded today.
Use 'mock' flag to tell package rest that you would like to use mockups.
exit status 2
FAIL github.com/jayzyaj/bookstore_oauth-api/src/repositories/external-api 0.307s
I have go 1.15.2 and am using GoLand 2020.2. I'm getting "Use 'mock' flag to tell package rest that you would like to use mockups" even though I've get rest.StartMockupServer() specified
As DevAgani pointed out, the problem seems to be in the func init() for mockup.go where it looks like the command line is being looked at to see if a -mock is being passed in. If you comment out the flag.Parse() the tests run ok. Not sure what changed, maybe GoLand used to pass a mock into the Unit Test command line, and now it doesn't? Whatever the reason, the pull request above solves the issue too.
This still seems to be an issue.
Hello there, I'm trying to run tests with this library in go1.19.4
darwin/arm64
Unfortunately getting a log error when trying to pass the mocks flags in code as in the terminal.
Davids-MBP-14-M1:rest david.gamboa$ go test -mock
flag provided but not defined: -test.paniconexit0
Usage of /var/folders/47/yy34nm7x16j16bl5t_7bbtd40000gt/T/go-build111689661/b001/rest.test:
-mock
Use 'mock' flag to tell package rest that you would like to use mockups.
exit status 2
FAIL github.com/BFDavidGamboa/bookstore_oauth-api/src/repository/rest 0.385s
This is the code for users_repository_test.go file
package rest
import (
"net/http"
"os"
"testing"
"github.com/mercadolibre/golang-restclient/rest"
"github.com/stretchr/testify/assert"
)
func TestMain(m *testing.M) {
rest.StartMockupServer()
os.Exit(m.Run())
}
func TestLoginUserTimeoutFromApi(t *testing.T) {
rest.FlushMockups()
rest.AddMockups(&rest.Mock{
HTTPMethod: http.MethodPost,
URL: "https://api.bookstore.com/users/login",
ReqBody: "{"email":"email@gmail.com","password":"the-password"}",
RespHTTPCode: -1,
RespBody: "{}",
})
repository := usersRepository{}
user, err := repository.LoginUser("email@gmail.com", "the-password")
assert.Nil(t, user)
assert.NotNil(t, err)
assert.EqualValues(t, http.StatusInternalServerError, err.Status)
assert.EqualValues(t, "invalid restclient response when trying to login user", err.Message)
}