From f64402e5c5499f99394967868aa24a1d4b022c3d Mon Sep 17 00:00:00 2001 From: Domenico Rizzo Date: Tue, 19 Nov 2024 17:54:58 +0100 Subject: [PATCH] MM-61519 Fix errcheck in channels/app/plugin_api_tests/test_update_user_auth_plugin/main.go (#29284) * Removed test_update_user_auth_plugin from golangci The test_update_user_auth_plugin has been removed from the .golangci.yml configuration file. This change simplifies the linting process by excluding unnecessary files. * Refactored error handling in user auth tests The error handling for the 'expectUserAuth' function within the user authentication plugin tests has been refactored. Previously, errors were not being explicitly checked after each call to this function. Now, an error check is performed after each invocation and if an error is found, it's immediately returned. This change improves the robustness of our test suite by ensuring that potential issues are caught and handled appropriately during testing. * Refactor error handling in UpdateUserAuth The error handling in the UpdateUserAuth function has been refactored. The variable 'err' was replaced with 'appErr' to better reflect its purpose and improve code readability. * Updated user authentication in plugin API The user authentication method in the plugin API has been updated. Previously, it was fetching the user based on a static configuration value. Now, it fetches the user dynamically using the provided userID. This change makes the function more flexible and adaptable to different use cases. * Updated golangci configuration Removed a test file from the exclusion list in the golangci.yml configuration. This will allow linting checks to be performed on this previously excluded file, improving code quality and consistency. * Updated golangci configuration Removed a test file from the exclusion list in the golangci configuration. This will ensure that our linting tools also cover this previously excluded test file, improving overall code quality checks. --------- Co-authored-by: Ben Schumacher --- server/.golangci.yml | 1 - .../test_update_user_auth_plugin/main.go | 26 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/server/.golangci.yml b/server/.golangci.yml index 82066925d1..f11ca30ff8 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -117,7 +117,6 @@ issues: channels/app/platform/web_conn.go|\ channels/app/platform/web_hub.go|\ channels/app/platform/web_hub_test.go|\ - channels/app/plugin_api_tests/test_update_user_auth_plugin/main.go|\ channels/app/plugin_install.go|\ channels/app/plugin_signature.go|\ channels/app/plugin_signature_test.go|\ diff --git a/server/channels/app/plugin_api_tests/test_update_user_auth_plugin/main.go b/server/channels/app/plugin_api_tests/test_update_user_auth_plugin/main.go index dd83b3d891..df7e9a4a53 100644 --- a/server/channels/app/plugin_api_tests/test_update_user_auth_plugin/main.go +++ b/server/channels/app/plugin_api_tests/test_update_user_auth_plugin/main.go @@ -24,7 +24,7 @@ func (p *MyPlugin) OnConfigurationChange() error { } func (p *MyPlugin) expectUserAuth(userID string, expectedUserAuth *model.UserAuth) error { - user, err := p.API.GetUser(p.configuration.BasicUserID) + user, err := p.API.GetUser(userID) if err != nil { return err } @@ -63,21 +63,33 @@ func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model return nil, appErr.Error() } - p.expectUserAuth(p.configuration.BasicUserID, expectedUserAuth) - p.expectUserAuth(p.configuration.BasicUser2Id, expectedUser2Auth) + err := p.expectUserAuth(p.configuration.BasicUserID, expectedUserAuth) + if err != nil { + return nil, err.Error() + } + err = p.expectUserAuth(p.configuration.BasicUser2Id, expectedUser2Auth) + if err != nil { + return nil, err.Error() + } // Update BasicUser to LDAP expectedUserAuth = &model.UserAuth{ AuthService: model.UserAuthServiceLdap, AuthData: model.NewPointer("ldap_auth_data"), } - _, err := p.API.UpdateUserAuth(p.configuration.BasicUserID, expectedUserAuth) + _, appErr = p.API.UpdateUserAuth(p.configuration.BasicUserID, expectedUserAuth) + if appErr != nil { + return nil, appErr.Error() + } + + err = p.expectUserAuth(p.configuration.BasicUserID, expectedUserAuth) + if err != nil { + return nil, err.Error() + } + err = p.expectUserAuth(p.configuration.BasicUser2Id, expectedUser2Auth) if err != nil { return nil, err.Error() } - - p.expectUserAuth(p.configuration.BasicUserID, expectedUserAuth) - p.expectUserAuth(p.configuration.BasicUser2Id, expectedUser2Auth) return nil, "OK" }