mattermost / mattermost-plugin-servicenow

ServiceNow plugin for Mattermost
Apache License 2.0
5 stars 5 forks source link

API tests fail #179

Open hanzei opened 1 year ago

hanzei commented 1 year ago

A lof of the test in /server/plugin/api_test.go fail with a NPE when trying to get the user in https://github.com/mattermost/mattermost-plugin-servicenow/blob/aa24737743fafb92884793a056c03052feb26cc3/server/plugin/user.go#L86.

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/mux@v1.8.0/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 commented 1 year ago

The monkey patching in https://github.com/mattermost/mattermost-plugin-servicenow/blob/aa24737743fafb92884793a056c03052feb26cc3/server/plugin/api_test.go#L46-L48 seems to be jenky. 3/5 that it should be replaced by a proper mocked function.