From be05cde1186097b61d1bef486e47b0da08bf4258 Mon Sep 17 00:00:00 2001 From: Bick Doner Date: Tue, 17 Jan 2023 20:51:29 +0100 Subject: [PATCH 1/2] Add error to printed message when plugin fails to open --- lib/remote/scanner.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/remote/scanner.go b/lib/remote/scanner.go index 465ef009d..5532eef0f 100644 --- a/lib/remote/scanner.go +++ b/lib/remote/scanner.go @@ -2,9 +2,10 @@ package remote import ( "fmt" - "github.com/sundowndev/phoneinfoga/v2/lib/number" "os" "plugin" + + "github.com/sundowndev/phoneinfoga/v2/lib/number" ) type Plugin interface { @@ -25,7 +26,7 @@ func OpenPlugin(path string) error { _, err := plugin.Open(path) if err != nil { - return fmt.Errorf("given plugin %s is not valid", path) + return fmt.Errorf("given plugin %s is not valid: %v", path, err) } return nil From 88c8b9deb73a3919f8dc17f93b547c3e66ccacb6 Mon Sep 17 00:00:00 2001 From: Bdoner Date: Fri, 20 Jan 2023 11:02:01 +0100 Subject: [PATCH 2/2] Update test to reflect code changes. --- lib/remote/scanner_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/remote/scanner_test.go b/lib/remote/scanner_test.go index becf6fdb9..9de53afa3 100644 --- a/lib/remote/scanner_test.go +++ b/lib/remote/scanner_test.go @@ -1,11 +1,19 @@ package remote import ( - "github.com/stretchr/testify/assert" + "fmt" + "path/filepath" "testing" + + "github.com/stretchr/testify/assert" ) func Test_ValidatePlugin_Errors(t *testing.T) { + invalidPluginAbsPath, err := filepath.Abs("testdata/invalid.so") + if err != nil { + assert.FailNow(t, "failed to get the absolute path of test file: %v", err) + } + testcases := []struct { name string path string @@ -19,7 +27,7 @@ func Test_ValidatePlugin_Errors(t *testing.T) { { name: "test with invalid plugin", path: "testdata/invalid.so", - wantErr: "given plugin testdata/invalid.so is not valid", + wantErr: fmt.Sprintf("given plugin testdata/invalid.so is not valid: plugin.Open(\"testdata/invalid.so\"): %s: file too short", invalidPluginAbsPath), }, }