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:
@@ -4,7 +4,9 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestIsBenignPipeReadError(t *testing.T) {
|
||||
@@ -30,3 +32,24 @@ func TestIsBenignPipeReadError(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessTracker_TrackUntrack(t *testing.T) {
|
||||
pt := NewProcessTracker()
|
||||
cmd := exec.Command("sh", "-c", "sleep 1")
|
||||
pt.Track(1, cmd)
|
||||
if count := pt.Count(); count != 1 {
|
||||
t.Fatalf("Count() = %d, want 1", count)
|
||||
}
|
||||
pt.Untrack(1)
|
||||
if count := pt.Count(); count != 0 {
|
||||
t.Fatalf("Count() = %d, want 0", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunCommandWithTimeout_TimesOut(t *testing.T) {
|
||||
pt := NewProcessTracker()
|
||||
_, err := RunCommandWithTimeout(200*time.Millisecond, "sh", []string{"-c", "sleep 2"}, "", nil, 99, pt)
|
||||
if err == nil {
|
||||
t.Fatal("expected timeout error")
|
||||
}
|
||||
}
|
||||
|
||||
19
pkg/scripts/scripts_test.go
Normal file
19
pkg/scripts/scripts_test.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package scripts
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEmbeddedScripts_ArePresent(t *testing.T) {
|
||||
if strings.TrimSpace(ExtractMetadata) == "" {
|
||||
t.Fatal("ExtractMetadata script should not be empty")
|
||||
}
|
||||
if strings.TrimSpace(UnhideObjects) == "" {
|
||||
t.Fatal("UnhideObjects script should not be empty")
|
||||
}
|
||||
if strings.TrimSpace(RenderBlenderTemplate) == "" {
|
||||
t.Fatal("RenderBlenderTemplate should not be empty")
|
||||
}
|
||||
}
|
||||
|
||||
49
pkg/types/types_test.go
Normal file
49
pkg/types/types_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestJobJSON_RoundTrip(t *testing.T) {
|
||||
now := time.Now().UTC().Truncate(time.Second)
|
||||
frameStart, frameEnd := 1, 10
|
||||
format := "PNG"
|
||||
job := Job{
|
||||
ID: 42,
|
||||
UserID: 7,
|
||||
JobType: JobTypeRender,
|
||||
Name: "demo",
|
||||
Status: JobStatusPending,
|
||||
Progress: 12.5,
|
||||
FrameStart: &frameStart,
|
||||
FrameEnd: &frameEnd,
|
||||
OutputFormat: &format,
|
||||
BlendMetadata: &BlendMetadata{
|
||||
FrameStart: 1,
|
||||
FrameEnd: 10,
|
||||
RenderSettings: RenderSettings{
|
||||
ResolutionX: 1920,
|
||||
ResolutionY: 1080,
|
||||
FrameRate: 24.0,
|
||||
},
|
||||
},
|
||||
CreatedAt: now,
|
||||
}
|
||||
|
||||
raw, err := json.Marshal(job)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal failed: %v", err)
|
||||
}
|
||||
|
||||
var out Job
|
||||
if err := json.Unmarshal(raw, &out); err != nil {
|
||||
t.Fatalf("unmarshal failed: %v", err)
|
||||
}
|
||||
|
||||
if out.ID != job.ID || out.JobType != JobTypeRender || out.BlendMetadata == nil {
|
||||
t.Fatalf("unexpected roundtrip result: %+v", out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user