Skip to content

Commit

Permalink
fix lint and ut
Browse files Browse the repository at this point in the history
Signed-off-by: liubo02 <[email protected]>
  • Loading branch information
liubog2008 committed Dec 24, 2024
1 parent 9474fd4 commit a1bdc82
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
17 changes: 8 additions & 9 deletions pkg/client/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ func NewFakeClient(objs ...client.Object) FakeClient {
}
}

func (fc *fakeClient) WithError(verb, resource string, err error) {
fc.fc.PrependReactor(verb, resource, func(action testing.Action) (bool, runtime.Object, error) {
return true, nil, err
})
}

type fakeClient struct {
Client
fc *fakeUnderlayClient
}

func (fc *fakeClient) WithError(verb, resource string, err error) {
fc.fc.PrependReactor(verb, resource, func(_ testing.Action) (bool, runtime.Object, error) {
return true, nil, err
})
}

type fakeUnderlayClient struct {
testing.Fake
tracker testing.ObjectTracker
Expand Down Expand Up @@ -586,11 +586,10 @@ func (c *fakeUnderlayClient) PatchReactionFunc(action *testing.PatchActionImpl)
}
case types.ApplyPatchType:
patchObj := &unstructured.Unstructured{Object: map[string]any{}}
if err = yaml.Unmarshal(action.GetPatch(), &patchObj.Object); err != nil {
if err := yaml.Unmarshal(action.GetPatch(), &patchObj.Object); err != nil {
return true, nil, fmt.Errorf("error decoding YAML: %w", err)
}
obj, err = manager.Apply(obj, patchObj, "tidb-operator", true)
if err != nil {
if _, err := manager.Apply(obj, patchObj, "tidb-operator", true); err != nil {
return true, nil, err
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/cluster/tasks/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func TestFinalizer(t *testing.T) {
},
{
desc: "removed finalizer",
cluster: fake.FakeObj[v1alpha1.Cluster]("test",
fake.SetDeleteTimestamp[v1alpha1.Cluster](), fake.AddFinalizer[v1alpha1.Cluster]()),
cluster: fake.FakeObj("test",
fake.DeleteNow[v1alpha1.Cluster](), fake.AddFinalizer[v1alpha1.Cluster]()),
expected: task.Complete().Break().With("removed finalizer"),
},
{
desc: "deleting components",
cluster: fake.FakeObj[v1alpha1.Cluster]("test",
fake.SetDeleteTimestamp[v1alpha1.Cluster](), fake.AddFinalizer[v1alpha1.Cluster]()),
cluster: fake.FakeObj("test",
fake.DeleteNow[v1alpha1.Cluster](), fake.AddFinalizer[v1alpha1.Cluster]()),
pdGroup: fake.FakeObj[v1alpha1.PDGroup]("pd-group"),
expected: task.Fail().With("deleting components"),
hasFinalizer: true,
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/pd/tasks/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type ReconcileContext struct {
}

func TaskContextInfoFromPD(state *ReconcileContext, cm pdm.PDClientManager) task.Task {
return task.NameTaskFunc("ContextInfoFromPD", func(ctx context.Context) task.Result {
return task.NameTaskFunc("ContextInfoFromPD", func(_ context.Context) task.Result {
ck := state.Cluster()
pc, ok := cm.Get(pdm.PrimaryKey(ck.Namespace, ck.Name))
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/pd/tasks/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TaskStatusSuspend(state *ReconcileContext, c client.Client) task.Task {
}

func TaskStatusUnknown() task.Task {
return task.NameTaskFunc("StatusUnknown", func(ctx context.Context) task.Result {
return task.NameTaskFunc("StatusUnknown", func(_ context.Context) task.Result {
return task.Wait().With("status of the pd is unknown")
})
}
Expand Down

0 comments on commit a1bdc82

Please sign in to comment.