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 wantErr bool }{ { 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: "whitespace only is stop-job", input: []byte(`E: " "`), want: ErrorActionStopJob, }, { name: "empty 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, }, { name: "error on invalid value", input: []byte(`E: invalid`), wantErr: true, }, } 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 tt.wantErr { assert.Error(t, err) return } if !assert.NoError(t, err) { return } assert.Equal(t, tt.want, placeholder.E) }) } } 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) }) } }