in internal/testutil/testutil.go [346:401]
func WithFakeExecutor(t *testing.T, mgr *Manager, sh execution.SynthesizerHandle) {
cli := mgr.GetAPIReader()
podCtrl := reconcile.Func(func(ctx context.Context, r reconcile.Request) (reconcile.Result, error) {
pod := &corev1.Pod{}
err := cli.Get(ctx, r.NamespacedName, pod)
if err != nil {
return reconcile.Result{}, client.IgnoreNotFound(err)
}
if pod.DeletionTimestamp != nil {
return reconcile.Result{}, nil
}
env := &execution.Env{}
for _, e := range pod.Spec.Containers[0].Env {
switch e.Name {
case "COMPOSITION_NAME":
env.CompositionName = e.Value
case "COMPOSITION_NAMESPACE":
env.CompositionNamespace = e.Value
case "SYNTHESIS_UUID":
env.SynthesisUUID = e.Value
case "IMAGE":
env.Image = e.Value
}
}
e := &execution.Executor{
Reader: cli,
Writer: mgr.GetClient(),
Handler: sh,
}
err = e.Synthesize(ctx, env)
if err != nil {
// Returning an error from the synth would eventually result in a timeout.
// To avoid waiting that long in the tests we can just delete the pod after the first try.
return reconcile.Result{}, mgr.GetClient().Delete(ctx, pod)
}
err = mgr.GetClient().Get(ctx, client.ObjectKeyFromObject(pod), pod)
if err != nil {
return reconcile.Result{}, nil
}
pod.Status.Phase = corev1.PodSucceeded
err = mgr.GetClient().Status().Update(ctx, pod)
if err != nil {
return reconcile.Result{}, nil
}
return reconcile.Result{}, nil
})
_, err := ctrl.NewControllerManagedBy(mgr.Manager).
For(&corev1.Pod{}).
Build(podCtrl)
require.NoError(t, err)
}