Add tests for main package, manager, and various components
- Introduced unit tests for the main package to ensure compilation. - Added tests for the manager, including validation of upload sessions and handling of Blender binary paths. - Implemented tests for job token generation and validation, ensuring security and integrity. - Created tests for configuration management and database schema to verify functionality. - Added tests for logger and runner components to enhance overall test coverage and reliability.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -44,8 +45,12 @@ func (m *Manager) GetBinaryPath(version string) (string, error) {
|
||||
if binaryInfo, err := os.Stat(binaryPath); err == nil {
|
||||
// Verify it's actually a file (not a directory)
|
||||
if !binaryInfo.IsDir() {
|
||||
log.Printf("Found existing Blender %s installation at %s", version, binaryPath)
|
||||
return binaryPath, nil
|
||||
absBinaryPath, err := ResolveBinaryPath(binaryPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
log.Printf("Found existing Blender %s installation at %s", version, absBinaryPath)
|
||||
return absBinaryPath, nil
|
||||
}
|
||||
}
|
||||
// Version folder exists but binary is missing - might be incomplete installation
|
||||
@@ -72,20 +77,50 @@ func (m *Manager) GetBinaryPath(version string) (string, error) {
|
||||
return "", fmt.Errorf("blender binary not found after extraction")
|
||||
}
|
||||
|
||||
log.Printf("Blender %s installed at %s", version, binaryPath)
|
||||
return binaryPath, nil
|
||||
absBinaryPath, err := ResolveBinaryPath(binaryPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
log.Printf("Blender %s installed at %s", version, absBinaryPath)
|
||||
return absBinaryPath, nil
|
||||
}
|
||||
|
||||
// GetBinaryForJob returns the Blender binary path for a job.
|
||||
// Uses the version from metadata or falls back to system blender.
|
||||
func (m *Manager) GetBinaryForJob(version string) (string, error) {
|
||||
if version == "" {
|
||||
return "blender", nil // System blender
|
||||
return ResolveBinaryPath("blender")
|
||||
}
|
||||
|
||||
return m.GetBinaryPath(version)
|
||||
}
|
||||
|
||||
// ResolveBinaryPath resolves a Blender executable to an absolute path.
|
||||
func ResolveBinaryPath(blenderBinary string) (string, error) {
|
||||
if blenderBinary == "" {
|
||||
return "", fmt.Errorf("blender binary path is empty")
|
||||
}
|
||||
|
||||
if strings.Contains(blenderBinary, string(filepath.Separator)) {
|
||||
absPath, err := filepath.Abs(blenderBinary)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to resolve blender binary path %q: %w", blenderBinary, err)
|
||||
}
|
||||
return absPath, nil
|
||||
}
|
||||
|
||||
resolvedPath, err := exec.LookPath(blenderBinary)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to locate blender binary %q in PATH: %w", blenderBinary, err)
|
||||
}
|
||||
absPath, err := filepath.Abs(resolvedPath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to resolve blender binary path %q: %w", resolvedPath, err)
|
||||
}
|
||||
return absPath, nil
|
||||
}
|
||||
|
||||
// TarballEnv returns a copy of baseEnv with LD_LIBRARY_PATH set so that a
|
||||
// tarball Blender installation can find its bundled libs (e.g. lib/python3.x).
|
||||
// If blenderBinary is the system "blender" or has no path component, baseEnv is
|
||||
|
||||
34
internal/runner/blender/binary_test.go
Normal file
34
internal/runner/blender/binary_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package blender
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResolveBinaryPath_AbsoluteLikePath(t *testing.T) {
|
||||
got, err := ResolveBinaryPath("./blender")
|
||||
if err != nil {
|
||||
t.Fatalf("ResolveBinaryPath failed: %v", err)
|
||||
}
|
||||
if !filepath.IsAbs(got) {
|
||||
t.Fatalf("expected absolute path, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveBinaryPath_Empty(t *testing.T) {
|
||||
if _, err := ResolveBinaryPath(""); err == nil {
|
||||
t.Fatal("expected error for empty blender binary")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTarballEnv_SetsAndExtendsLDLibraryPath(t *testing.T) {
|
||||
bin := filepath.Join(string(os.PathSeparator), "tmp", "blender", "blender")
|
||||
got := TarballEnv(bin, []string{"A=B", "LD_LIBRARY_PATH=/old"})
|
||||
joined := strings.Join(got, "\n")
|
||||
if !strings.Contains(joined, "LD_LIBRARY_PATH=/tmp/blender/lib:/old") {
|
||||
t.Fatalf("expected LD_LIBRARY_PATH to include blender lib, got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
32
internal/runner/blender/detect_test.go
Normal file
32
internal/runner/blender/detect_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package blender
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestIsDRMCardNode(t *testing.T) {
|
||||
tests := map[string]bool{
|
||||
"card0": true,
|
||||
"card12": true,
|
||||
"card": false,
|
||||
"card0-DP-1": false,
|
||||
"renderD128": false,
|
||||
"foo": false,
|
||||
}
|
||||
for in, want := range tests {
|
||||
if got := isDRMCardNode(in); got != want {
|
||||
t.Fatalf("isDRMCardNode(%q) = %v, want %v", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsGPUControllerLine(t *testing.T) {
|
||||
if !isGPUControllerLine("vga compatible controller: nvidia corp") {
|
||||
t.Fatal("expected VGA controller line to match")
|
||||
}
|
||||
if !isGPUControllerLine("3d controller: amd") {
|
||||
t.Fatal("expected 3d controller line to match")
|
||||
}
|
||||
if isGPUControllerLine("audio device: something") {
|
||||
t.Fatal("audio line should not match")
|
||||
}
|
||||
}
|
||||
|
||||
34
internal/runner/blender/logfilter_test.go
Normal file
34
internal/runner/blender/logfilter_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package blender
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"jiggablend/pkg/types"
|
||||
)
|
||||
|
||||
func TestFilterLog_FiltersNoise(t *testing.T) {
|
||||
cases := []string{
|
||||
"",
|
||||
"--------------------------------------------------------------------",
|
||||
"Failed to add relation foo",
|
||||
"BKE_modifier_set_error",
|
||||
"Depth Type Name",
|
||||
}
|
||||
for _, in := range cases {
|
||||
filtered, level := FilterLog(in)
|
||||
if !filtered {
|
||||
t.Fatalf("expected filtered for %q", in)
|
||||
}
|
||||
if level != types.LogLevelInfo {
|
||||
t.Fatalf("unexpected level for %q: %s", in, level)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterLog_KeepsNormalLine(t *testing.T) {
|
||||
filtered, _ := FilterLog("Rendering done.")
|
||||
if filtered {
|
||||
t.Fatal("normal line should not be filtered")
|
||||
}
|
||||
}
|
||||
|
||||
10
internal/runner/blender/version_test.go
Normal file
10
internal/runner/blender/version_test.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package blender
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestVersionString(t *testing.T) {
|
||||
if got := VersionString(4, 2); got != "4.2" {
|
||||
t.Fatalf("VersionString() = %q, want %q", got, "4.2")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user