Something went wrong on our end
Select Git revision
Monster.Namespace.html
-
Volker Schukai authoredVolker Schukai authored
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")
}
}