QBitRun/lib/workflow/job_test.go

71 lines
1.3 KiB
Go
Raw Normal View History

package workflow
import (
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
func TestErrorAction_UnmarshalYAML(t *testing.T) {
tests := []struct {
name string
input []byte
want ErrorAction
}{
{
name: "continue",
input: []byte(`E: ConTinue`),
want: ErrorActionContinue,
},
{
name: "stop-job",
input: []byte(`E: stop-job`),
want: ErrorActionStopJob,
},
{
name: "stop-job",
input: []byte(`E: stop-job`),
want: ErrorActionStopJob,
},
{
name: "null is stop-job",
input: []byte(`E: null`),
want: ErrorActionStopJob,
},
{
name: "unset is stop-job",
input: []byte(`E: `),
want: ErrorActionStopJob,
},
{
name: "unset is stop-job 2",
input: []byte(`foo: bar`),
want: ErrorActionStopJob,
},
{
name: "stop-action",
input: []byte(`E: stop-action`),
want: ErrorActionStopAction,
},
{
name: "stop-run",
input: []byte(`E: stop-run`),
want: ErrorActionStopRun,
},
}
type placeholder struct {
E ErrorAction `yaml:"E"`
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var placeholder placeholder
err := yaml.Unmarshal(tt.input, &placeholder)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, tt.want, placeholder.E)
})
}
}