Skip to content
Snippets Groups Projects
Select Git revision
  • d3986decc562c4208e22443f6fc277f64dbb9063
  • master default protected
  • 1.31
  • 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
  • 4.23.1
  • 4.23.0
  • 4.22.3
23 results

monster.iml

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