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

API tests fail #179

Open
hanzei opened this issue Apr 11, 2023 · 1 comment
Open

API tests fail #179

hanzei opened this issue Apr 11, 2023 · 1 comment
Labels
Difficulty/1:Easy Easy ticket Help Wanted Community help wanted Tech/Go Type/Bug Something isn't working Up For Grabs Ready for help from the community. Removed when someone volunteers

Comments

@hanzei
Copy link
Contributor

hanzei commented Apr 11, 2023

A lof of the test in /server/plugin/api_test.go fail with a NPE when trying to get the user in

storedUser, err := p.store.LoadUser(mattermostUserID)
.

E.g. TestAPISearchRecordsInServiceNow fails with:

-- FAIL: TestAPISearchRecordsInServiceNow (0.00s)
    --- FAIL: TestAPISearchRecordsInServiceNow/failed_to_get_records (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic:

mock: Unexpected Method Call
-----------------------------

LogError(string,string,string,string,runtime.errorString,string,string)
		0: "Recovered from a panic"
		1: "URL"
		2: "/api/v1/records/incident?search=sss"
		3: "Error"
		4: "invalid memory address or nil pointer dereference"
		5: "Stack"
		6: "goroutine 13 [running]:\nruntime/debug.Stack()\n\t/usr/local/go/src/runtime/debug/stack.go:24 +0x65\ngithub.com/mattermost/mattermost-plugin-servicenow/server/plugin.(*Plugin).withRecovery.func1.1()\n\t/go/src/mattermost/plugins/servicenow/server/plugin/api.go:818 +0x74\npanic({0x1854a80, 0x2bd29f0})\n\t/usr/local/go/src/runtime/panic.go:884 +0x212\ngithub.com/mattermost/mattermost-plugin-servicenow/server/plugin.(*Plugin).GetUser(...)\n\t/go/src/mattermost/plugins/servicenow/server/plugin/user.go:86\ngithub.com/mattermost/mattermost-plugin-servicenow/server/plugin.(*Plugin).checkOAuth.func1({0x1ed9610, 0xc000f295c0}, 0xc00018ed00)\n\t/go/src/mattermost/plugins/servicenow/server/plugin/api.go:77 +0x75\ngithub.com/mattermost/mattermost-plugin-servicenow/server/plugin.(*Plugin).checkAuth.func1({0x1ed9610, 0xc000f295c0}, 0xc00018ed00)\n\t/go/src/mattermost/plugins/servicenow/server/plugin/api.go:70 +0xba\nnet/http.HandlerFunc.ServeHTTP(0xf8?, {0x1ed96
10?, 0xc000f295c0?}, 0xc000f3bb60?)\n\t/usr/local/go/src/net/http/server.go:2109 +0x2f\ngithub.com/mattermost/mattermost-plugin-servicenow/server/plugin.(*Plugin).withRecovery.func1({0x1ed9610?, 0xc000f295c0?}, 0xc001062930?)\n\t/go/src/mattermost/plugins/servicenow/server/plugin/api.go:822 +0x85\nnet/http.HandlerFunc.ServeHTTP(0xc00018ec00?, {0x1ed9610?, 0xc000f295c0?}, 0xd0e658?)\n\t/usr/local/go/src/net/http/server.go:2109 +0x2f\ngithub.com/gorilla/mux.(*Router).ServeHTTP(0xc00037c480, {0x1ed9610, 0xc000f295c0}, 0xc00018eb00)\n\t/go/go/pkg/mod/github.com/gorilla/[email protected]/mux.go:210 +0x1cf\ngithub.com/mattermost/mattermost-plugin-servicenow/server/plugin.(*Plugin).ServeHTTP(...)\n\t/go/src/mattermost/plugins/servicenow/server/plugin/plugin.go:56\ngithub.com/mattermost/mattermost-plugin-servicenow/server/plugin.TestAPISearchRecordsInServiceNow.func9(0xc0004e91e0)\n\t/go/src/mattermost/plugins/servicenow/server/plugin/api_test.go:282 +0x44f\ntesting.tR
unner(0xc0004e91e0, 0xc000ed4760)\n\t/usr/local/go/src/testing/testing.go:1446 +0x10b\ncreated by testing.(*T).Run\n\t/usr/local/go/src/testing/testing.go:1493 +0x35f\n"
@hanzei hanzei added the Type/Bug Something isn't working label Apr 11, 2023
@hanzei
Copy link
Contributor Author

hanzei commented Apr 11, 2023

The monkey patching in

monkey.PatchInstanceMethod(reflect.TypeOf(p), "GetUser", func(_ *Plugin, _ string) (*serializer.User, error) {
return testutils.GetSerializerUser(), nil
})
seems to be jenky. 3/5 that it should be replaced by a proper mocked function.

@hanzei hanzei added Help Wanted Community help wanted Up For Grabs Ready for help from the community. Removed when someone volunteers Difficulty/1:Easy Easy ticket Tech/Go labels Apr 11, 2023
mickmister added a commit that referenced this issue May 8, 2024
mickmister added a commit that referenced this issue May 8, 2024
* [GH-179]: Fixed the API testcase by adding the flag

* Empty-Commit to retrigger workflow

---------

Co-authored-by: Antonis Stamatiou <[email protected]>
Co-authored-by: Michael Kochell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty/1:Easy Easy ticket Help Wanted Community help wanted Tech/Go Type/Bug Something isn't working Up For Grabs Ready for help from the community. Removed when someone volunteers
Projects
None yet
Development

No branches or pull requests

1 participant