-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move validator to *_validator.go. Changes with validator "transition"…
… and "end" validator: add to BaseState; fix failed unit tests; refactor SwitchState validator. Signed-off-by: André R. de Miranda <andre@galgo.tech>
- Loading branch information
1 parent
994a77d
commit 5bb51f0
Showing
34 changed files
with
1,572 additions
and
1,165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2021 The Serverless Workflow Specification Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package model | ||
|
||
import ( | ||
"reflect" | ||
|
||
validator "github.com/go-playground/validator/v10" | ||
val "github.com/serverlessworkflow/sdk-go/v2/validator" | ||
) | ||
|
||
func init() { | ||
val.GetValidator().RegisterStructValidation(eventStructLevelValidation, Event{}) | ||
} | ||
|
||
// eventStructLevelValidation custom validator for event kind consumed | ||
func eventStructLevelValidation(structLevel validator.StructLevel) { | ||
event := structLevel.Current().Interface().(Event) | ||
if event.Kind == EventKindConsumed && len(event.Type) == 0 { | ||
structLevel.ReportError(reflect.ValueOf(event.Type), "Type", "type", "reqtypeconsumed", "") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2021 The Serverless Workflow Specification Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package model | ||
|
||
import ( | ||
"testing" | ||
|
||
val "github.com/serverlessworkflow/sdk-go/v2/validator" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestEventRefStructLevelValidation(t *testing.T) { | ||
type testCase struct { | ||
name string | ||
eventRef EventRef | ||
err string | ||
} | ||
|
||
testCases := []testCase{ | ||
{ | ||
name: "valid resultEventTimeout", | ||
eventRef: EventRef{ | ||
TriggerEventRef: "example valid", | ||
ResultEventRef: "example valid", | ||
ResultEventTimeout: "PT1H", | ||
Invoke: InvokeKindSync, | ||
}, | ||
err: ``, | ||
}, | ||
{ | ||
name: "invalid resultEventTimeout", | ||
eventRef: EventRef{ | ||
TriggerEventRef: "example invalid", | ||
ResultEventRef: "example invalid red", | ||
ResultEventTimeout: "10hs", | ||
Invoke: InvokeKindSync, | ||
}, | ||
err: `Key: 'EventRef.ResultEventTimeout' Error:Field validation for 'ResultEventTimeout' failed on the 'iso8601duration' tag`, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := val.GetValidator().Struct(tc.eventRef) | ||
|
||
if tc.err != "" { | ||
assert.Error(t, err) | ||
assert.Regexp(t, tc.err, err) | ||
return | ||
} | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.