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) } }