Files
jiggablend/internal/runner/runner_test.go
T
s1d3sw1ped 1a69fcfd04 Refactor installation and runner scripts for enhanced usability and security
- Updated the installation script to clarify that production wrappers do not include fixed test secrets, improving user guidance for local testing.
- Modified the jiggablend-manager and jiggablend-runner scripts to remove fixed test configurations, emphasizing the use of local test credentials via `make init-test`.
- Enhanced error handling in the runner script to ensure that an API key is provided, improving security and user feedback.
- Added new flags and options for the runner, including sandboxing capabilities and GPU ray tracing control, enhancing flexibility for users.
- Improved README documentation to reflect changes in usage and configuration, ensuring users have clear instructions for setup and execution.
2026-07-12 10:01:15 -05:00

97 lines
2.5 KiB
Go

package runner
import (
"encoding/hex"
"errors"
"os"
"path/filepath"
"testing"
)
func TestNewRunner_InitializesFields(t *testing.T) {
r := New("http://localhost:8080", "runner-a", "host-a", false, false, 0)
if r == nil {
t.Fatal("New should return a runner")
}
if r.name != "runner-a" || r.hostname != "host-a" {
t.Fatalf("unexpected runner identity: %q %q", r.name, r.hostname)
}
}
func TestRunner_GPUFlagsSetters(t *testing.T) {
r := New("http://localhost:8080", "runner-a", "host-a", false, false, 0)
if newly := r.SetGPULockedOut(true); !newly {
t.Fatal("expected first SetGPULockedOut(true) to report newly enabled")
}
if !r.IsGPULockedOut() {
t.Fatal("expected GPU lockout to be true")
}
if newly := r.SetGPULockedOut(true); newly {
t.Fatal("expected second SetGPULockedOut(true) to be a no-op transition")
}
if newly := r.SetGPULockedOut(false); newly {
t.Fatal("clearing lockout should not report newly enabled")
}
if r.IsGPULockedOut() {
t.Fatal("expected GPU lockout cleared")
}
}
func TestGenerateFingerprint_PopulatesValue(t *testing.T) {
r := New("http://localhost:8080", "runner-a", "host-a", false, false, 0)
r.generateFingerprint()
fp := r.GetFingerprint()
if fp == "" {
t.Fatal("fingerprint should not be empty")
}
if len(fp) != 64 {
t.Fatalf("fingerprint should be sha256 hex, got %q", fp)
}
if _, err := hex.DecodeString(fp); err != nil {
t.Fatalf("fingerprint should be valid hex: %v", err)
}
}
func TestUploadOutputFiles_FailsWhenUploadErrors(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "frame_0001.exr"), []byte("x"), 0644); err != nil {
t.Fatal(err)
}
err := uploadOutputFiles(dir, func(filePath, fileName string) error {
return errors.New("upload denied")
})
if err == nil {
t.Fatal("expected error when upload fails")
}
}
func TestUploadOutputFiles_FailsWhenEmpty(t *testing.T) {
dir := t.TempDir()
err := uploadOutputFiles(dir, func(filePath, fileName string) error {
t.Fatal("upload should not be called")
return nil
})
if err == nil {
t.Fatal("expected error for empty output dir")
}
}
func TestUploadOutputFiles_Success(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "frame_0001.exr"), []byte("x"), 0644); err != nil {
t.Fatal(err)
}
var seen string
err := uploadOutputFiles(dir, func(filePath, fileName string) error {
seen = fileName
return nil
})
if err != nil {
t.Fatalf("uploadOutputFiles: %v", err)
}
if seen != "frame_0001.exr" {
t.Fatalf("got %q", seen)
}
}