Skip to content
Snippets Groups Projects
Select Git revision
  • 27964ab40a230ffe46012d165ee0ca5da472958e
  • master default protected
  • 1.31
  • 4.29.1
  • 4.29.0
  • 4.28.0
  • 4.27.0
  • 4.26.0
  • 4.25.5
  • 4.25.4
  • 4.25.3
  • 4.25.2
  • 4.25.1
  • 4.25.0
  • 4.24.3
  • 4.24.2
  • 4.24.1
  • 4.24.0
  • 4.23.6
  • 4.23.5
  • 4.23.4
  • 4.23.3
  • 4.23.2
23 results

.devenv.flake.nix

Blame
  • job_test.go 3.91 KiB
    package jobqueue
    
    import (
    	"context"
    	"github.com/stretchr/testify/assert"
    	"os"
    	"path"
    	"testing"
    	"time"
    )
    
    func TestNewJob(t *testing.T) {
    	runner := &ShellRunnable{ScriptPath: "path"}
    	job := NewJob[ShellResult]("id1", runner)
    	assert.Equal(t, JobID("id1"), job.GetID())
    	assert.Equal(t, PriorityDefault, job.GetPriority())
    }
    
    func TestSetPriority(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	job.SetPriority(PriorityHigh)
    	assert.Equal(t, PriorityHigh, job.GetPriority())
    }
    
    func TestSetAndGetTimeout(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	job.SetTimeout(5 * time.Minute)
    	assert.Equal(t, 5*time.Minute, job.GetTimeout())
    }
    
    func TestSetAndGetMaxRetries(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	job.SetMaxRetries(5)
    	assert.Equal(t, uint(5), job.GetMaxRetries())
    }
    
    func TestSetAndGetRunnable(t *testing.T) {
    	runner := &ShellRunnable{ScriptPath: "path"}
    	job := NewJob[ShellResult]("id1", runner)
    	assert.Equal(t, runner, job.GetRunnable())
    }
    
    func TestSetAndGetRetryDelay(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	job.SetRetryDelay(2 * time.Second)
    	assert.Equal(t, 2*time.Second, job.GetRetryDelay())
    }
    
    func TestSetAndGetDependencies(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	job.SetDependencies([]JobID{"id2", "id3"})
    	assert.Equal(t, []JobID{"id2", "id3"}, job.GetDependencies())
    }
    
    type TestScheduler struct{}
    
    func (s *TestScheduler) Schedule(job *GenericJob, eventBus *EventBus, stopChan chan bool) error {
    	return nil
    }
    
    func TestGetID(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	assert.Equal(t, JobID("id1"), job.GetID())
    }
    
    func TestGetRunnable(t *testing.T) {
    	runner := &ShellRunnable{ScriptPath: "path"}
    	job := NewJob[ShellResult]("id1", runner)
    	assert.Equal(t, runner, job.GetRunnable())
    }