mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-07 17:29:39 -06:00
* feat: namespaced python * wip: namespaced go * fix: service name * fix: tests * feat: client WithNamespace * feat: namespace example * feat: namespaced event triggers * docs: namespace docs * chore: linting --------- Co-authored-by: gabriel ruttner <gabe@hatchet.run>
76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package worker
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func namedFunction() {}
|
|
|
|
func TestGetFnNameAnon(t *testing.T) {
|
|
fn := func() {}
|
|
|
|
name := getFnName(fn)
|
|
|
|
if name != "TestGetFnNameAnon-func1" {
|
|
t.Fatalf("expected function name to be TestGetFnNameAnon-func1, got %s", name)
|
|
}
|
|
|
|
name = getFnName(func() {})
|
|
|
|
if name != "TestGetFnNameAnon-func2" {
|
|
t.Fatalf("expected function name to be TestGetFnNameAnon-func2, got %s", name)
|
|
}
|
|
|
|
name = getFnName(namedFunction)
|
|
|
|
if name != "namedFunction" {
|
|
t.Fatalf("expected function name to be namedFunction, got %s", name)
|
|
}
|
|
}
|
|
|
|
type actionInput struct {
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type stepOneOutput struct {
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type stepTwoOutput struct {
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
func TestToWorkflowJob(t *testing.T) {
|
|
testJob := WorkflowJob{
|
|
Name: "test",
|
|
Description: "test",
|
|
Steps: []*WorkflowStep{
|
|
{
|
|
Function: func(ctx context.Context, input *actionInput) (result *stepOneOutput, err error) {
|
|
return nil, nil
|
|
},
|
|
},
|
|
{
|
|
Function: func(ctx context.Context, input *stepOneOutput) (result *stepTwoOutput, err error) {
|
|
return nil, nil
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
workflow := testJob.ToWorkflow("default", "")
|
|
|
|
assert.Equal(t, "test", workflow.Name)
|
|
}
|
|
|
|
func TestFnToWorkflow(t *testing.T) {
|
|
workflow := Fn(func(ctx context.Context, input *actionInput) (result *stepOneOutput, err error) {
|
|
return nil, nil
|
|
}).ToWorkflow("default", "")
|
|
|
|
assert.Equal(t, "TestFnToWorkflow-func1", workflow.Name)
|
|
}
|