|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | + |
| 21 | +package reconcile |
| 22 | + |
| 23 | +import ( |
| 24 | + "context" |
| 25 | + "testing" |
| 26 | + |
| 27 | + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" |
| 28 | + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" |
| 29 | + inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" |
| 30 | + "github.com/rs/zerolog" |
| 31 | + "github.com/rs/zerolog/log" |
| 32 | + "github.com/stretchr/testify/require" |
| 33 | +) |
| 34 | + |
| 35 | +func Test_PlanBuilderAppender_Recovery(t *testing.T) { |
| 36 | + t.Run("Recover", func(t *testing.T) { |
| 37 | + require.Len(t, recoverPlanAppender(log.Logger, newPlanAppender(NewWithPlanBuilder(context.Background(), zerolog.Logger{}, nil, api.DeploymentSpec{}, api.DeploymentStatus{}, nil, nil), nil)). |
| 38 | + Apply(func(_ context.Context, _ zerolog.Logger, _ k8sutil.APIObject, _ api.DeploymentSpec, _ api.DeploymentStatus, _ inspectorInterface.Inspector, _ PlanBuilderContext) api.Plan { |
| 39 | + panic("") |
| 40 | + }). |
| 41 | + Apply(func(_ context.Context, _ zerolog.Logger, _ k8sutil.APIObject, _ api.DeploymentSpec, _ api.DeploymentStatus, _ inspectorInterface.Inspector, _ PlanBuilderContext) api.Plan { |
| 42 | + panic("SomePanic") |
| 43 | + }).Plan(), 0) |
| 44 | + }) |
| 45 | + t.Run("Recover with output", func(t *testing.T) { |
| 46 | + require.Len(t, recoverPlanAppender(log.Logger, newPlanAppender(NewWithPlanBuilder(context.Background(), zerolog.Logger{}, nil, api.DeploymentSpec{}, api.DeploymentStatus{}, nil, nil), nil)). |
| 47 | + Apply(func(_ context.Context, _ zerolog.Logger, _ k8sutil.APIObject, _ api.DeploymentSpec, _ api.DeploymentStatus, _ inspectorInterface.Inspector, _ PlanBuilderContext) api.Plan { |
| 48 | + return api.Plan{api.Action{}} |
| 49 | + }). |
| 50 | + ApplyIfEmpty(func(_ context.Context, _ zerolog.Logger, _ k8sutil.APIObject, _ api.DeploymentSpec, _ api.DeploymentStatus, _ inspectorInterface.Inspector, _ PlanBuilderContext) api.Plan { |
| 51 | + panic("SomePanic") |
| 52 | + }). |
| 53 | + ApplyIfEmpty(func(_ context.Context, _ zerolog.Logger, _ k8sutil.APIObject, _ api.DeploymentSpec, _ api.DeploymentStatus, _ inspectorInterface.Inspector, _ PlanBuilderContext) api.Plan { |
| 54 | + return api.Plan{api.Action{}, api.Action{}} |
| 55 | + }).Plan(), 1) |
| 56 | + }) |
| 57 | + t.Run("Recover with multi", func(t *testing.T) { |
| 58 | + require.Len(t, recoverPlanAppender(log.Logger, newPlanAppender(NewWithPlanBuilder(context.Background(), zerolog.Logger{}, nil, api.DeploymentSpec{}, api.DeploymentStatus{}, nil, nil), nil)). |
| 59 | + Apply(func(_ context.Context, _ zerolog.Logger, _ k8sutil.APIObject, _ api.DeploymentSpec, _ api.DeploymentStatus, _ inspectorInterface.Inspector, _ PlanBuilderContext) api.Plan { |
| 60 | + return api.Plan{api.Action{}} |
| 61 | + }). |
| 62 | + ApplyIfEmpty(func(_ context.Context, _ zerolog.Logger, _ k8sutil.APIObject, _ api.DeploymentSpec, _ api.DeploymentStatus, _ inspectorInterface.Inspector, _ PlanBuilderContext) api.Plan { |
| 63 | + panic("SomePanic") |
| 64 | + }). |
| 65 | + Apply(func(_ context.Context, _ zerolog.Logger, _ k8sutil.APIObject, _ api.DeploymentSpec, _ api.DeploymentStatus, _ inspectorInterface.Inspector, _ PlanBuilderContext) api.Plan { |
| 66 | + return api.Plan{api.Action{}, api.Action{}} |
| 67 | + }).Plan(), 3) |
| 68 | + }) |
| 69 | +} |
0 commit comments