- 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.
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package executils
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"os"
|
|
"os/exec"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestIsBenignPipeReadError(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
err error
|
|
want bool
|
|
}{
|
|
{name: "nil", err: nil, want: false},
|
|
{name: "eof", err: io.EOF, want: true},
|
|
{name: "closed", err: os.ErrClosed, want: true},
|
|
{name: "closed pipe", err: io.ErrClosedPipe, want: true},
|
|
{name: "wrapped closed", err: errors.New("read |0: file already closed"), want: true},
|
|
{name: "other", err: errors.New("permission denied"), want: false},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := isBenignPipeReadError(tc.err)
|
|
if got != tc.want {
|
|
t.Fatalf("got %v, want %v (err=%v)", got, tc.want, tc.err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
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")
|
|
}
|
|
}
|