test: fix CompilePlugin test helper (#30644)

This PR fixes CompilePlugin which would fail when run locally in certain
situations based on relative directory paths. This change makes
CompilePlugin perform os.Stat on the full path to the plugin's main.go
file to ensure the test changes to the appropriate directory for
building the plugin.
This commit is contained in:
John-Michael Faircloth 2025-05-15 15:42:44 -05:00 committed by GitHub
parent 8fb58b5859
commit 86651479c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -76,10 +76,6 @@ func CompilePlugin(t testing.TB, typ consts.PluginType, pluginVersion string, pl
var pluginBytes []byte
dir := ""
pluginRootDir := "builtin"
if typ == consts.PluginTypeDatabase {
pluginRootDir = "plugins"
}
for {
// So that we can assign to dir without overshadowing the other
// err variables.
@ -89,7 +85,7 @@ func CompilePlugin(t testing.TB, typ consts.PluginType, pluginVersion string, pl
t.Fatal(getWdErr)
}
// detect if we are in a subdirectory or the root directory and compensate
if _, err := os.Stat(pluginRootDir); os.IsNotExist(err) {
if _, err := os.Stat(pluginMain); os.IsNotExist(err) {
err := os.Chdir("..")
if err != nil {
t.Fatal(err)