Skip to content
Snippets Groups Projects
Select Git revision
  • fafc34f8f9295ac0b8bcd6903b33e89d6ab6fb09
  • master default protected
  • v1.23.2
  • v1.23.1
  • v1.23.0
  • v1.22.0
  • v1.21.1
  • v1.21.0
  • v1.20.3
  • v1.20.2
  • v1.20.1
  • v1.20.0
  • v1.19.4
  • v1.19.3
  • v1.19.2
  • v1.19.1
  • v1.19.0
  • v1.18.2
  • v1.18.1
  • v1.18.0
  • v1.17.0
  • v1.16.1
22 results

runnable_test.go

Blame
  • runnable_test.go 1.94 KiB
    package jobqueue
    
    import (
    	"context"
    	"errors"
    	"testing"
    )
    
    // MockSuccessfulRunnable gibt immer ResultStatusSuccess zurück
    type MockSuccessfulRunnable struct{}
    
    func (m MockSuccessfulRunnable) Run(ctx context.Context) (RunResult[string], error) {
    	return RunResult[string]{Status: ResultStatusSuccess, Data: "Success"}, nil
    }
    
    // MockFailedRunnable gibt immer ResultStatusFailed zurück
    type MockFailedRunnable struct{}
    
    func (m MockFailedRunnable) Run(ctx context.Context) (RunResult[string], error) {
    	return RunResult[string]{Status: ResultStatusFailed, Data: "Failed"}, nil
    }
    
    // MockErrorRunnable gibt immer einen Fehler zurück
    type MockErrorRunnable struct{}
    
    func (m MockErrorRunnable) Run(ctx context.Context) (RunResult[string], error) {
    	return RunResult[string]{}, errors.New("RunError")
    }
    
    func (m MockErrorRunnable) GetType() string {
    	return "mock-error"
    }
    
    func (m MockFailedRunnable) GetType() string {
    	return "mock-failed"
    }
    
    func (m MockSuccessfulRunnable) GetType() string {
    	return "mock-success"
    }
    
    func (m MockErrorRunnable) GetPersistence() RunnableImport {
    	return RunnableImport{}
    }
    
    func (m MockFailedRunnable) GetPersistence() RunnableImport {
    	return RunnableImport{}
    }
    func (m MockSuccessfulRunnable) GetPersistence() RunnableImport {
    	return RunnableImport{}
    }
    
    func TestRunnable(t *testing.T) {
    	var run Runnable[string]
    
    	ctx := context.Background()
    
    	// Test für erfolgreiche Ausführung
    	run = MockSuccessfulRunnable{}
    	result, err := run.Run(ctx)
    	if result.Status != ResultStatusSuccess || err != nil {
    		t.Errorf("Expected success, got %v, %v", result.Status, err)
    	}
    
    	// Test für fehlgeschlagene Ausführung
    	run = MockFailedRunnable{}
    	result, err = run.Run(ctx)
    	if result.Status != ResultStatusFailed || err != nil {
    		t.Errorf("Expected failure, got %v, %v", result.Status, err)
    	}
    
    	// Test für Ausführungsfehler
    	run = MockErrorRunnable{}
    	result, err = run.Run(ctx)
    	if err == nil {
    		t.Errorf("Expected error, got nil")
    	}
    }