Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Out to WaitBuilder #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions builtin/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func NewWait(name string) *WaitBuilder {
return &WaitBuilder{task: task}
}

func (b *WaitBuilder) Output(output map[string]any) *WaitBuilder {
b.task.Input.Output = orchestrator.Expr[map[string]any]{Expr: output}
return b
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai generate unit testing code for this file.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RussellLuo, here's the unit testing code for the builtin/wait.go file, focusing on the WaitBuilder and Wait structs:

package builtin_test

import (
	"context"
	"testing"
	"github.com/stretchr/testify/assert"
	"github.com/RussellLuo/orchestrator/builtin"
	"github.com/RussellLuo/orchestrator"
)

func TestWaitBuilder_Output(t *testing.T) {
	builder := builtin.NewWait("testWait")
	outputMap := map[string]any{"key": "value"}
	resultBuilder := builder.Output(outputMap)

	assert.Equal(t, outputMap, resultBuilder.Task.Input.Output.Expr, "Output should set the output map correctly")
}

func TestWaitBuilder_Build(t *testing.T) {
	builder := builtin.NewWait("testWait")
	resultTask := builder.Build()

	assert.IsType(t, &builtin.Wait{}, resultTask, "Build should return a Wait task")
	assert.Equal(t, "testWait", resultTask.Name, "Task name should be set correctly")
}

func TestWait_Execute(t *testing.T) {
	ctx := context.Background()
	input := orchestrator.Input{}
	task := &builtin.Wait{
		TaskHeader: orchestrator.TaskHeader{Name: "testWait", Type: "wait"},
	}

	// Mock behavior
	behavior := &mockActorBehavior{}
	input.Set("actor", map[string]any{"behavior": behavior})

	output, err := task.Execute(ctx, input)

	assert.Nil(t, err, "Should handle nil input without error")
	assert.NotNil(t, output, "Should return an output")
}

// Mock ActorBehavior for testing
type mockActorBehavior struct {
	orchestrator.ActorBehavior
}

func (m *mockActorBehavior) Send(data map[string]any, err error) {
	// Mock sending data
}

func (m *mockActorBehavior) Receive() map[string]any {
	// Mock receiving data
	return map[string]any{"key": "value"}
}

This includes basic tests for the Output and Build methods of WaitBuilder, and a more complex test for the Execute method of Wait, which involves mocking the ActorBehavior. You might need to adjust the mock implementations based on the actual behavior and interfaces in your application.

func (b *WaitBuilder) Build() orchestrator.Task {
return b.task
}
Loading