@@ -2,10 +2,16 @@ package controller
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "strings"
78 "testing"
89
10+ "k8s.io/client-go/tools/events"
11+ "sigs.k8s.io/controller-runtime/pkg/client"
12+ "sigs.k8s.io/controller-runtime/pkg/client/fake"
13+ "sigs.k8s.io/controller-runtime/pkg/client/interceptor"
14+
915 flyteorgv1 "github.com/flyteorg/flyte/v2/executor/api/v1"
1016 pluginsCore "github.com/flyteorg/flyte/v2/flyteplugins/go/tasks/pluginmachinery/core"
1117)
@@ -109,3 +115,38 @@ func TestValidateTaskAction_PluginNotFound(t *testing.T) {
109115 t .Errorf ("expected reason %q, got %q" , flyteorgv1 .ConditionReasonPluginNotFound , reason )
110116 }
111117}
118+
119+ func TestReconcileTask_ValidationStatusUpdate (t * testing.T ) {
120+ statusErr := errors .New ("status update failed" )
121+ for _ , tc := range []struct {
122+ name string
123+ updateErr error
124+ }{
125+ {name : "success" },
126+ {name : "failure" , updateErr : statusErr },
127+ } {
128+ t .Run (tc .name , func (t * testing.T ) {
129+ k8sClient := fake .NewClientBuilder ().
130+ WithInterceptorFuncs (interceptor.Funcs {
131+ SubResourceUpdate : func (context.Context , client.Client , string , client.Object , ... client.SubResourceUpdateOption ) error {
132+ return tc .updateErr
133+ },
134+ }).
135+ Build ()
136+ reconciler := & TaskActionReconciler {
137+ Client : k8sClient ,
138+ Recorder : events .NewFakeRecorder (1 ),
139+ }
140+ taskAction := validTaskAction ()
141+ taskAction .Spec .RunName = ""
142+
143+ _ , err := reconciler .reconcileTask (context .Background (), taskAction , taskAction .DeepCopy ())
144+ if ! errors .Is (err , tc .updateErr ) {
145+ t .Fatalf ("expected %v, got %v" , tc .updateErr , err )
146+ }
147+ if ! isTerminal (taskAction ) {
148+ t .Fatal ("expected validation failure to remain terminal" )
149+ }
150+ })
151+ }
152+ }
0 commit comments