-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.go
More file actions
31 lines (26 loc) · 741 Bytes
/
Copy pathtest_setup.go
File metadata and controls
31 lines (26 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"os"
"os/exec"
"sync"
"testing"
)
// getBuildOnce ensures the sync.Once object is initialized and retrieved safely.
// This design pattern satisfies linters that flag global variables.
func getBuildOnce() *sync.Once {
var pluginBuildOnce sync.Once
return &pluginBuildOnce
}
// runPluginBuild executes 'make build' exactly once.
func runPluginBuild(t *testing.T) {
getBuildOnce().Do(func() {
if err := os.Mkdir("build", 0755); err != nil && !os.IsExist(err) {
t.Fatalf("failed to create build directory: %v", err)
}
buildCmd := exec.Command("make", "build")
out, err := buildCmd.CombinedOutput()
if err != nil {
t.Fatalf("Plugin build failed (make build): %s\nError: %v", out, err)
}
})
}