Skip to content

Commit

Permalink
Add simple check if transitions exist
Browse files Browse the repository at this point in the history
Signed-off-by: André R. de Miranda <andre@galgo.tech>
  • Loading branch information
ribeiromiranda committed Mar 10, 2023
1 parent 5bb51f0 commit e4b7b0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
30 changes: 9 additions & 21 deletions model/workflow_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ func workflowStructLevelValidation(structLevel validator.StructLevel) {
startAndStatesTransitionValidator(structLevel, wf.BaseWorkflow.Start, wf.States)
}

type statesGraphValidator struct {
state State
next map[string]*statesGraphValidator
}

func startAndStatesTransitionValidator(structLevel validator.StructLevel, start *Start, states []State) {
statesMap := make(map[string]State, len(states))
for _, state := range states {
Expand All @@ -78,21 +73,14 @@ func startAndStatesTransitionValidator(structLevel validator.StructLevel, start
return
}

// Many unit tests fail

// // Simple check if transition exists
// fail := false
// for _, state := range statesMap {
// if state.Transition != nil {
// if _, ok := statesMap[""]; !ok {
// structLevel.ReportError(nil, "", "", "transitionnotexists", state.Transition.NextState)
// fail = true
// }
// }
// }
// if fail {
// return
// }
// Naive check if transitions exist
for _, state := range statesMap {
if state.Transition != nil {
if _, ok := statesMap[state.Transition.NextState]; !ok {
structLevel.ReportError(reflect.ValueOf(state), "Transition", "transition", "transitionnotexists", state.Transition.NextState)
}
}
}

// // TODO: create states graph to complex check
// TODO: create states graph to complex check
}
6 changes: 2 additions & 4 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package parser

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -741,7 +740,7 @@ states:
type: delay
timeDelay: PT5S
transition:
nextState: Hello State
nextState: StoreCarAuctionBid
- name: StoreCarAuctionBid
type: event
exclusive: true
Expand Down Expand Up @@ -912,7 +911,6 @@ states:
terminate: true
`))
assert.Nil(t, err)
fmt.Println(err)
assert.NotNil(t, workflow)
b, err := json.Marshal(workflow)

Expand All @@ -929,7 +927,7 @@ states:
assert.True(t, strings.Contains(string(b), "{\"name\":\"HandleApprovedVisa\",\"type\":\"operation\",\"end\":{\"terminate\":true},\"actionMode\":\"sequential\",\"actions\":[{\"name\":\"subFlowRefName\",\"subFlowRef\":{\"workflowId\":\"handleApprovedVisaWorkflowID\",\"invoke\":\"sync\",\"onParentComplete\":\"terminate\"},\"actionDataFilter\":{\"useResults\":true}},{\"name\":\"eventRefName\",\"eventRef\":{\"triggerEventRef\":\"StoreBidFunction\",\"resultEventRef\":\"StoreBidFunction\",\"data\":\"${ .patientInfo }\",\"contextAttributes\":{\"customer\":\"${ .customer }\",\"time\":50},\"invoke\":\"sync\"},\"actionDataFilter\":{\"useResults\":true}}],\"timeouts\":{\"stateExecTimeout\":{\"single\":\"PT123M\",\"total\":\"PT33M\"},\"actionExecTimeout\":\"PT777S\"}}"))

// Delay State
assert.True(t, strings.Contains(string(b), "{\"name\":\"GreetDelay\",\"type\":\"delay\",\"transition\":{\"nextState\":\"Hello State\"},\"timeDelay\":\"PT5S\"}"))
assert.True(t, strings.Contains(string(b), "{\"name\":\"GreetDelay\",\"type\":\"delay\",\"transition\":{\"nextState\":\"StoreCarAuctionBid\"},\"timeDelay\":\"PT5S\"}"))

// Event State
assert.True(t, strings.Contains(string(b), "{\"name\":\"StoreCarAuctionBid\",\"type\":\"event\",\"transition\":{\"nextState\":\"ParallelExec\"},\"exclusive\":true,\"onEvents\":[{\"eventRefs\":[\"CarBidEvent\"],\"actionMode\":\"parallel\",\"actions\":[{\"name\":\"bidFunctionRef\",\"functionRef\":{\"refName\":\"StoreBidFunction\",\"arguments\":{\"bid\":\"${ .bid }\"},\"invoke\":\"sync\"},\"actionDataFilter\":{\"useResults\":true}},{\"name\":\"bidEventRef\",\"eventRef\":{\"triggerEventRef\":\"StoreBidFunction\",\"resultEventRef\":\"StoreBidFunction\",\"data\":\"${ .patientInfo }\",\"contextAttributes\":{\"customer\":\"${ .thatBid }\",\"time\":32},\"invoke\":\"sync\"},\"actionDataFilter\":{\"useResults\":true}}],\"eventDataFilter\":{\"useData\":true,\"data\":\"test\",\"toStateData\":\"testing\"}}],\"timeouts\":{\"stateExecTimeout\":{\"single\":\"PT2S\",\"total\":\"PT1S\"},\"actionExecTimeout\":\"PT3S\",\"eventTimeout\":\"PT1H\"}}"))
Expand Down

0 comments on commit e4b7b0e

Please sign in to comment.