2024-06-25 16:50:13 +07:00
|
|
|
package workflow
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestErrorAction_UnmarshalYAML(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-06-25 16:55:52 +07:00
|
|
|
name string
|
|
|
|
input []byte
|
|
|
|
want ErrorAction
|
|
|
|
wantErr bool
|
2024-06-25 16:50:13 +07:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
},
|
2024-06-25 16:53:41 +07:00
|
|
|
{
|
|
|
|
name: "whitespace only is stop-job",
|
|
|
|
input: []byte(`E: " "`),
|
|
|
|
want: ErrorActionStopJob,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty is stop-job",
|
|
|
|
input: []byte(`E: ""`),
|
|
|
|
want: ErrorActionStopJob,
|
|
|
|
},
|
2024-06-25 16:50:13 +07:00
|
|
|
{
|
|
|
|
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,
|
|
|
|
},
|
2024-06-25 16:55:52 +07:00
|
|
|
{
|
|
|
|
name: "error on invalid value",
|
|
|
|
input: []byte(`E: invalid`),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2024-06-25 16:50:13 +07:00
|
|
|
}
|
|
|
|
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)
|
2024-06-25 16:55:52 +07:00
|
|
|
if tt.wantErr {
|
|
|
|
assert.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
2024-06-25 16:50:13 +07:00
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.Equal(t, tt.want, placeholder.E)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2024-06-25 17:12:30 +07:00
|
|
|
|
|
|
|
func TestErrorAction_MarshalYAML(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
er ErrorAction
|
|
|
|
want []byte
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "continue",
|
|
|
|
er: ErrorActionContinue,
|
|
|
|
want: []byte("E: continue"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "stop-job",
|
|
|
|
er: ErrorActionStopJob,
|
|
|
|
want: []byte("E: stop-job"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "stop-action",
|
|
|
|
er: ErrorActionStopAction,
|
|
|
|
want: []byte("E: stop-action"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "stop-run",
|
|
|
|
er: ErrorActionStopRun,
|
|
|
|
want: []byte("E: stop-run"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
type placeholder struct {
|
|
|
|
E ErrorAction `yaml:"E"`
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
e := placeholder{E: tt.er}
|
|
|
|
got, err := yaml.Marshal(e)
|
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.Equal(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|