Skip to content

Commit 2d156fb

Browse files
committedJun 27, 2022
add UT
1 parent 6b40333 commit 2d156fb

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed
 

‎pkg/deployment/reconcile/plan_builder_test.go

+38-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package reconcile
2323
import (
2424
"context"
2525
"fmt"
26+
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
2627
"io/ioutil"
2728
"testing"
2829
"time"
@@ -49,7 +50,6 @@ import (
4950
"github.com/arangodb/kube-arangodb/pkg/deployment/patch"
5051
pod2 "github.com/arangodb/kube-arangodb/pkg/deployment/pod"
5152
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
52-
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
5353
"github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned"
5454
"github.com/arangodb/kube-arangodb/pkg/logging"
5555
"github.com/arangodb/kube-arangodb/pkg/util"
@@ -81,13 +81,13 @@ type testContext struct {
8181
PVC *core.PersistentVolumeClaim
8282
PVCErr error
8383
RecordedEvent *k8sutil.Event
84+
ArangoTask *api.ArangoTask
8485

8586
Inspector inspectorInterface.Inspector
8687
}
8788

8889
func (c *testContext) GetNextTask(ctx context.Context) (*api.ArangoTask, error) {
89-
//TODO implement me
90-
panic("implement me")
90+
return c.ArangoTask, nil
9191
}
9292

9393
func (c *testContext) GetAgencyHealth() (agencyCache.Health, bool) {
@@ -696,6 +696,7 @@ type testCase struct {
696696
ExpectedError error
697697
ExpectedPlan api.Plan
698698
ExpectedHighPlan api.Plan
699+
ExpectedTaskPlan api.Plan
699700
ExpectedLog string
700701
ExpectedEvent *k8sutil.Event
701702

@@ -761,6 +762,17 @@ func TestCreatePlan(t *testing.T) {
761762
addAgentsToStatus(t, &deploymentTemplate.Status, 3)
762763
deploymentTemplate.Spec.SetDefaults("createPlanTest")
763764

765+
arangoTaskTemplate := &api.ArangoTask{
766+
ObjectMeta: meta.ObjectMeta{
767+
Name: "test_task",
768+
Namespace: tests.FakeNamespace,
769+
},
770+
Spec: api.ArangoTaskSpec{
771+
Type: api.ArangoTaskPingType,
772+
DeploymentName: "test_depl",
773+
},
774+
}
775+
764776
testCases := []testCase{
765777
{
766778
Name: "Can not create plan for single deployment",
@@ -1173,6 +1185,18 @@ func TestCreatePlan(t *testing.T) {
11731185
},
11741186
ExpectedLog: "Creating scale-down plan",
11751187
},
1188+
{
1189+
Name: "ArangoTask - ping type",
1190+
context: &testContext{
1191+
ArangoDeployment: deploymentTemplate.DeepCopy(),
1192+
ArangoTask: arangoTaskTemplate,
1193+
},
1194+
1195+
ExpectedTaskPlan: []api.Action{
1196+
actions.NewClusterAction(api.ActionTypePing, "Pinging database server"),
1197+
},
1198+
ExpectedLog: "Pinging database server",
1199+
},
11761200
}
11771201

11781202
for _, testCase := range testCases {
@@ -1242,6 +1266,17 @@ func TestCreatePlan(t *testing.T) {
12421266
assert.Equal(t, v.Reason, status.Plan[i].Reason)
12431267
}
12441268
}
1269+
1270+
if len(testCase.ExpectedTaskPlan) > 0 {
1271+
require.Len(t, status.TaskPlan, len(testCase.ExpectedTaskPlan))
1272+
for i, v := range testCase.ExpectedTaskPlan {
1273+
assert.Equal(t, v.Type, status.TaskPlan[i].Type)
1274+
assert.Equal(t, v.Group, status.TaskPlan[i].Group)
1275+
if v.Reason != "*" {
1276+
assert.Equal(t, v.Reason, status.TaskPlan[i].Reason)
1277+
}
1278+
}
1279+
}
12451280
})
12461281
}
12471282
}

0 commit comments

Comments
 (0)
Please sign in to comment.