Skip to content

Commit

Permalink
Added unit tests, and updated dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredoconnell committed Sep 9, 2024
1 parent e130517 commit de80c54
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
go.arcalot.io/assert v1.8.0
go.arcalot.io/dgraph v1.5.0
go.arcalot.io/dgraph v1.6.0
go.arcalot.io/lang v1.1.0
go.arcalot.io/log/v2 v2.2.0
go.flow.arcalot.io/deployer v0.6.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.arcalot.io/assert v1.8.0 h1:hGcHMPncQXwQvjj7MbyOu2gg8VIBB00crUJZpeQOjxs=
go.arcalot.io/assert v1.8.0/go.mod h1:nNmWPoNUHFyrPkNrD2aASm5yPuAfiWdB/4X7Lw3ykHk=
go.arcalot.io/dgraph v1.5.0 h1:6cGlxLzmmehJoD/nj0Hkql7uh90EU0A0GtZhGYkr28M=
go.arcalot.io/dgraph v1.5.0/go.mod h1:+Kxc81utiihMSmC1/ttSPGLDlWPpvgOpNxSFmIDPxFM=
go.arcalot.io/dgraph v1.6.0 h1:mJFZ1vdPEg3KtqyhNqYtWVAkxxWBWoJVUFZQ2Z4mbvE=
go.arcalot.io/dgraph v1.6.0/go.mod h1:+Kxc81utiihMSmC1/ttSPGLDlWPpvgOpNxSFmIDPxFM=
go.arcalot.io/exex v0.2.0 h1:u44pjwPwcH57TF8knhaqVZP/1V/KbnRe//pKzMwDpLw=
go.arcalot.io/exex v0.2.0/go.mod h1:5zlFr+7vOQNZKYCNOEDdsad+z/dlvXKs2v4kG+v+bQo=
go.arcalot.io/lang v1.1.0 h1:ugglRKpd3qIMkdghAjKJxsziIgHm8QpxrzZPSXoa08I=
Expand Down
98 changes: 97 additions & 1 deletion internal/infer/infer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package infer_test

import (
"fmt"
"go.arcalot.io/assert"
"go.arcalot.io/lang"
"go.flow.arcalot.io/expressions"
"testing"

"go.flow.arcalot.io/engine/internal/infer"
Expand All @@ -11,14 +14,29 @@ import (
type testEntry struct {
name string
input any
dataModel schema.Scope
expectedOutputType schema.TypeID
validate func(t schema.Type) error
}

var testOneOf = infer.OneOfExpression{
Discriminator: "option",
Options: map[string]any{
"a": map[string]any{
"value-1": 1,
},
"b": map[string]any{
"value-2": lang.Must2(expressions.New("$.a")),
},
},
Node: "n/a",
}

var testData = []testEntry{
{
"string",
"foo",
nil,
schema.TypeIDString,
func(t schema.Type) error {
return nil
Expand All @@ -30,6 +48,7 @@ var testData = []testEntry{
"foo": "bar",
"baz": 42,
},
nil,
schema.TypeIDObject,
func(t schema.Type) error {
objectSchema := t.(*schema.ObjectSchema)
Expand All @@ -46,6 +65,7 @@ var testData = []testEntry{
{
"slice",
[]string{"foo"},
nil,
schema.TypeIDList,
func(t schema.Type) error {
listType := t.(*schema.ListSchema)
Expand All @@ -55,19 +75,95 @@ var testData = []testEntry{
return nil
},
},
{
"expression-1",
lang.Must2(expressions.New("$.a")),
schema.NewScopeSchema(
schema.NewObjectSchema("root", map[string]*schema.PropertySchema{
"a": schema.NewPropertySchema(
schema.NewStringSchema(nil, nil, nil),
nil,
true,
nil,
nil,
nil,
nil,
nil,
),
}),
),
schema.TypeIDString,
func(t schema.Type) error {
return nil
},
},
{
"oneof-expression",
&testOneOf,
schema.NewScopeSchema(
schema.NewObjectSchema("root", map[string]*schema.PropertySchema{
"a": schema.NewPropertySchema(
schema.NewStringSchema(nil, nil, nil),
nil,
true,
nil,
nil,
nil,
nil,
nil,
),
}),
),
schema.TypeIDOneOfString,
func(t schema.Type) error {
return t.ValidateCompatibility(
schema.NewOneOfStringSchema[any](
map[string]schema.Object{
"a": schema.NewObjectSchema("n/a", map[string]*schema.PropertySchema{
"value-1": schema.NewPropertySchema(
schema.NewIntSchema(nil, nil, nil),
nil,
true,
nil,
nil,
nil,
nil,
nil,
),
}),
"b": schema.NewObjectSchema("n/a", map[string]*schema.PropertySchema{
"value-2": schema.NewPropertySchema(
schema.NewStringSchema(nil, nil, nil),
nil,
true,
nil,
nil,
nil,
nil,
nil,
),
}),
},
"option",
false,
),
)
},
},
}

func TestInfer(t *testing.T) {
for _, entry := range testData {
entry := entry
t.Run(entry.name, func(t *testing.T) {
inferredType, err := infer.Type(entry.input, nil, nil, nil)
inferredType, err := infer.Type(entry.input, entry.dataModel, nil, nil)
if err != nil {
t.Fatalf("%v", err)
}
if inferredType.TypeID() != entry.expectedOutputType {
t.Fatalf("Incorrect type inferred: %s", inferredType.TypeID())
}
assert.NoError(t, entry.validate(inferredType))
})
}

Expand Down
19 changes: 9 additions & 10 deletions workflow/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,13 @@ input:
root: RootObject
objects:
RootObject:
id: RootObject
id: RootObject
properties: {}
steps:
second_wait:
wait_for: !expr $.steps.first_wait.outputs.success
kind: foreach
items:
items:
- wait_time_ms: 10
workflow: subworkflow.yaml
first_wait:
Expand Down Expand Up @@ -608,7 +608,7 @@ input:
root: RootObject
objects:
RootObject:
id: RootObject
id: RootObject
properties: {}
steps:
pre_wait:
Expand All @@ -621,7 +621,7 @@ steps:
second_wait:
wait_for: !expr $.steps.first_wait.starting.started
kind: foreach
items:
items:
- wait_time_ms: 2
workflow: subworkflow.yaml
first_wait:
Expand Down Expand Up @@ -778,7 +778,6 @@ steps:
input:
wait_time_ms: 0
wait_2:
plugin:
src: "n/a"
deployment_type: "builtin"
Expand Down Expand Up @@ -995,8 +994,8 @@ outputSchema:
success:
schema:
root: RootObjectOut
objects:
RootObjectOut:
objects:
RootObjectOut:
id: RootObjectOut
properties: {}`

Expand Down Expand Up @@ -1386,7 +1385,7 @@ input:
root: RootObject
objects:
RootObject:
id: RootObject
id: RootObject
properties:
step_to_run:
type:
Expand Down Expand Up @@ -1814,7 +1813,7 @@ input:
root: RootObject
objects:
RootObject:
id: RootObject
id: RootObject
properties:
step_to_run:
type:
Expand All @@ -1838,7 +1837,7 @@ steps:
enabled: !expr $.input.step_to_run == "b"
subwf_step:
kind: foreach
items:
items:
- input_1: !oneof
discriminator: "result"
one_of:
Expand Down

0 comments on commit de80c54

Please sign in to comment.