Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Coverage Error #1477

Open
icywaffle opened this issue Nov 26, 2019 · 3 comments
Open

Test Coverage Error #1477

icywaffle opened this issue Nov 26, 2019 · 3 comments
Labels
type-bug waiting-for-reply Question raised, need answer
Projects

Comments

@icywaffle
Copy link

icywaffle commented Nov 26, 2019

The first issue that I ran into, trying to copy the Booking example in order to use go test for full coverage. When I was trying to use the Get method for the testing suite, it would instantly give me a

revel  panic.go:522: Recovered error in startup                error="runtime error: invalid memory address or nil pointer dereference"
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: Fatal error in startup
[signal 0xc0000005 code=0x0 addr=0x8 pc=0x631651]

After a few hours of debugging, I finally realized that this was actually the correct response for the test, because it was actually the Get method was appending the wrong URI, causing a panic into a test failure.

What I had to do was actually use GetCustom, and used this instead.

import(
	"testing"
	"github.com/revel/modules/server-engine/gohttptest/testsuite"
)
func TestForGETRequests(t *testing.T) {
	suite := testsuite.NewTestSuite(t)

	url := "http://" + suite.Host() + "/somePath"
	suite.GetCustom(url)
}

However, the Get method works normally using the normal test format from the main page tutorial, but I think it's better to use this way to get test coverage.

I was wondering why this was an issue, and if anyone ran into this issue too, I hope it helps.

@icywaffle icywaffle changed the title Testing Get and Booking Example Error Full Coverage Test Error Nov 26, 2019
@icywaffle icywaffle changed the title Full Coverage Test Error Test Coverage Error Nov 26, 2019
@icywaffle
Copy link
Author

At a closer look, GetCustom looked like it worked, but it actually does nothing. We don't get a response to decode, because there was nothing that decoded the response. When adding .Send() method at the end of it, it panics again.

Here is the stack trace,

goroutine 21 [running]:
github.com/revel/revel.Run.func1()
        C:/Users/Spots/go/src/github.com/revel/revel/server.go:70 +0x158
panic(0xaeac60, 0x11f6140)
        C:/Programming Languages/Go/src/runtime/panic.go:522 +0x1c3
net/url.(*URL).String(0x0, 0x85e578, 0xc000144448)
        C:/Programming Languages/Go/src/net/url/url.go:777 +0x51
ffxiv-profit-api/app.glob..func1(0xc00029a820, 0xc000144490, 0xd, 0xe)
        C:/Users/Spots/go/src/ffxiv-profit-api/app/init.go:65 +0xac
github.com/revel/revel.glob..func33(0xc00029a820, 0xc000144488, 0xe, 0xf)
        C:/Users/Spots/go/src/github.com/revel/revel/watcher.go:298 +0x84
github.com/revel/revel.handleInternal(0xd42bc0, 0xc000293060)
        C:/Users/Spots/go/src/github.com/revel/revel/server-engine.go:193 +0x3b9
github.com/revel/modules/server-engine/gohttptest/testsuite.(*GoHttpServer).Handle(0xc000278e40, 0xd4b800, 0xc0001a6e00, 0xc0003f7900)
        C:/Users/Spots/go/src/github.com/revel/modules/server-engine/gohttptest/testsuite/engine_adapter_go_httptest.go:108 +0x381
github.com/revel/modules/server-engine/gohttptest/testsuite.(*GoHttpServer).Start(0xc000278e40)
        C:/Users/Spots/go/src/github.com/revel/modules/server-engine/gohttptest/testsuite/engine_adapter_go_httptest.go:73 +0x98
github.com/revel/revel.Run(0xffffffffffffffff)
        C:/Users/Spots/go/src/github.com/revel/revel/server.go:88 +0x228
ffxiv-profit-api/app/tmp/run.Run(0xffffffffffffffff)
        C:/Users/Spots/go/src/test-application/app/tmp/run/run.go:28 +0x37
github.com/revel/modules/server-engine/gohttptest/testsuite.RevelTestHelper.func2(0xbcb950)
        C:/Users/Spots/go/src/github.com/revel/modules/server-engine/gohttptest/testsuite/test_helper.go:53 +0x36
created by github.com/revel/modules/server-engine/gohttptest/testsuite.RevelTestHelper
        C:/Users/Spots/go/src/github.com/revel/modules/server-engine/gohttptest/testsuite/test_helper.go:52 +0x283

@icywaffle
Copy link
Author

This also doesn't work for any of the other HTTP methods.

@brendensoares brendensoares added type-bug waiting-for-reply Question raised, need answer labels Feb 8, 2020
@brendensoares
Copy link
Member

@icywaffle did you find a solution? If not, can you reproduce the issue with a new revel app (revel new testapp)?

@notzippy notzippy added this to To do in Revel May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug waiting-for-reply Question raised, need answer
Projects
Revel
  
To do
Development

No branches or pull requests

2 participants