Skip to content

Commit

Permalink
Refactor fake logging (#1692)
Browse files Browse the repository at this point in the history
* Refactor fake logging, To #37688693

Signed-off-by: cheyang <cheyang@163.com>

* Refactor fake logging, To #37688693

Signed-off-by: cheyang <cheyang@163.com>

* Refactor fake logging, To #37688693

Signed-off-by: cheyang <cheyang@163.com>
  • Loading branch information
cheyang authored Mar 30, 2022
1 parent e018db9 commit bf3b453
Show file tree
Hide file tree
Showing 105 changed files with 422 additions and 533 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ ifeq (, $(shell which controller-gen))
cd $$CONTROLLER_GEN_TMP_DIR ;\
export GO111MODULE=on ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0 ;\
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
Expand Down
7 changes: 4 additions & 3 deletions pkg/controllers/v1alpha1/fluidapp/implement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
package fluidapp

import (
"testing"

"github.com/brahma-adshonor/gohook"
"github.com/fluid-cloudnative/fluid/pkg/common"
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"testing"
)

func TestFluidAppReconcilerImplement_umountFuseSidecar(t *testing.T) {
Expand Down Expand Up @@ -124,7 +125,7 @@ func TestFluidAppReconcilerImplement_umountFuseSidecar(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
i := &FluidAppReconcilerImplement{
Log: logr.New(log.NullLogSink{}),
Log: fake.NullLogger(),
}
if err := i.umountFuseSidecar(tt.args.pod); (err != nil) != tt.wantErr {
t.Errorf("umountFuseSidecar() error = %v, wantErr %v", err, tt.wantErr)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/v1alpha1/juicefs/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
package juicefs

import (
"github.com/go-logr/logr"
"path/filepath"
"testing"

Expand All @@ -30,6 +29,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
//+kubebuilder:scaffold:imports
)

Expand All @@ -49,7 +49,7 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func(done Done) {
logf.SetLogger(logr.New(logf.NullLogSink{}))
logf.SetLogger(fake.NullLogger())

By("bootstrapping test environment")
testEnv = &envtest.Environment{
Expand Down
4 changes: 1 addition & 3 deletions pkg/ctrl/affinity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ limitations under the License.
package ctrl

import (
"github.com/go-logr/logr"
"reflect"
"testing"

"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilpointer "k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/log"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
Expand Down Expand Up @@ -269,7 +267,7 @@ func TestBuildWorkersAffinity(t *testing.T) {
if err != nil {
t.Errorf("testcase %s failed due to %v", tt.name, err)
}
h := BuildHelper(runtimeInfo, mockClient, logr.New(log.NullLogSink{}))
h := BuildHelper(runtimeInfo, mockClient, fake.NullLogger())

want := tt.fields.want
worker, err := h.BuildWorkersAffinity(tt.fields.worker)
Expand Down
10 changes: 4 additions & 6 deletions pkg/ctrl/ctrl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ package ctrl

import (
"context"
"github.com/go-logr/logr"
"testing"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
utilpointer "k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/log"

appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
Expand All @@ -45,7 +43,7 @@ func TestCheckWorkerAffinity(t *testing.T) {
if err != nil {
t.Errorf("testcase %s failed due to %v", name, err)
}
h := BuildHelper(runtimeInfo, mockClient, logr.New(log.NullLogSink{}))
h := BuildHelper(runtimeInfo, mockClient, fake.NullLogger())

tests := []struct {
name string
Expand Down Expand Up @@ -364,7 +362,7 @@ func TestSetupWorkers(t *testing.T) {
runtimeObjs = append(runtimeObjs, data)
mockClient := fake.NewFakeClientWithScheme(s, runtimeObjs...)

h := BuildHelper(tt.fields.runtimeInfo, mockClient, logr.New(log.NullLogSink{}))
h := BuildHelper(tt.fields.runtimeInfo, mockClient, fake.NullLogger())

err := h.SetupWorkers(tt.fields.runtime, tt.fields.runtime.Status, &tt.fields.worker)

Expand Down Expand Up @@ -563,15 +561,15 @@ func TestCheckWorkersReady(t *testing.T) {
// name: tt.fields.name,
// namespace: tt.fields.namespace,
// Client: mockClient,
// Log: logr.New(log.NullLogSink{}),
// Log: fake.NullLogger(),
// }

runtimeInfo, err := base.BuildRuntimeInfo(tt.fields.name, tt.fields.namespace, "jindo", datav1alpha1.TieredStore{})
if err != nil {
t.Errorf("testcase %s failed due to %v", tt.fields.name, err)
}

h := BuildHelper(runtimeInfo, mockClient, logr.New(log.NullLogSink{}))
h := BuildHelper(runtimeInfo, mockClient, fake.NullLogger())

gotReady, err := h.CheckWorkersReady(tt.fields.runtime, tt.fields.runtime.Status, tt.fields.worker)

Expand Down
9 changes: 4 additions & 5 deletions pkg/ctrl/fuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)

var (
Expand Down Expand Up @@ -250,7 +249,7 @@ func TestCheckFuseHealthy(t *testing.T) {
t.Errorf("sync replicas failed,err:%s", err.Error())
}

h := BuildHelper(runtimeInfo, fakeClient, logr.New(log.NullLogSink{}))
h := BuildHelper(runtimeInfo, fakeClient, fake.NullLogger())

err = h.CheckFuseHealthy(record.NewFakeRecorder(300),
runtime, runtime.Status, ds)
Expand Down Expand Up @@ -308,7 +307,7 @@ func TestCleanUpFuse(t *testing.T) {
"node-select": "true",
},
},
log: logr.New(log.NullLogSink{}),
log: fake.NullLogger(),
runtimeType: "jindo",
nodeInputs: []*v1.Node{
{
Expand Down Expand Up @@ -362,7 +361,7 @@ func TestCleanUpFuse(t *testing.T) {
"node-select": "true",
},
},
log: logr.New(log.NullLogSink{}),
log: fake.NullLogger(),
runtimeType: "alluxio",
nodeInputs: []*v1.Node{
{
Expand Down Expand Up @@ -418,7 +417,7 @@ func TestCleanUpFuse(t *testing.T) {
"node-select": "true",
},
},
log: logr.New(log.NullLogSink{}),
log: fake.NullLogger(),
runtimeType: "goosefs",
nodeInputs: []*v1.Node{
{
Expand Down
4 changes: 1 addition & 3 deletions pkg/ctrl/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package ctrl

import (
"context"
"github.com/go-logr/logr"
"testing"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
Expand All @@ -31,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
utilpointer "k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/log"
)

func TestCheckMasterHealthy(t *testing.T) {
Expand Down Expand Up @@ -262,7 +260,7 @@ func TestCheckMasterHealthy(t *testing.T) {
t.Errorf("sync replicas failed,err:%s", err.Error())
}

h := BuildHelper(runtimeInfo, fakeClient, logr.New(log.NullLogSink{}))
h := BuildHelper(runtimeInfo, fakeClient, fake.NullLogger())

err = h.CheckMasterHealthy(record.NewFakeRecorder(300),
runtime, runtime.Status, statefulset)
Expand Down
8 changes: 3 additions & 5 deletions pkg/ctrl/replicas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package ctrl

import (
"context"
"github.com/go-logr/logr"
"testing"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
Expand All @@ -31,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
utilpointer "k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/log"
)

// func newAlluxioEngineREP(client client.Client, name string, namespace string) *alluxio.AlluxioEngine {
Expand All @@ -43,7 +41,7 @@ import (
// namespace: namespace,
// Client: client,
// runtimeInfo: runTimeInfo,
// Log: logr.New(log.NullLogSink{}),
// Log: fake.NullLogger(),
// }
// return engine
// }
Expand Down Expand Up @@ -277,9 +275,9 @@ func TestSyncReplicas(t *testing.T) {
t.Errorf("sync replicas failed,err:%s", err.Error())
}

h := BuildHelper(runtimeInfo, fakeClient, logr.New(log.NullLogSink{}))
h := BuildHelper(runtimeInfo, fakeClient, fake.NullLogger())
err = h.SyncReplicas(cruntime.ReconcileRequestContext{
Log: logr.New(log.NullLogSink{}),
Log: fake.NullLogger(),
Recorder: record.NewFakeRecorder(300),
}, runtime, runtime.Status, statefulset)

Expand Down
4 changes: 1 addition & 3 deletions pkg/ctrl/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ package ctrl

import (
"context"
"github.com/go-logr/logr"
"testing"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
fluiderrs "github.com/fluid-cloudnative/fluid/pkg/errors"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -403,7 +401,7 @@ func TestCheckWorkersHealthy(t *testing.T) {
t.Errorf("sync replicas failed,err:%s", err.Error())
}

h := BuildHelper(runtimeInfo, fakeClient, logr.New(log.NullLogSink{}))
h := BuildHelper(runtimeInfo, fakeClient, fake.NullLogger())

err = h.CheckWorkersHealthy(
record.NewFakeRecorder(300),
Expand Down
4 changes: 1 addition & 3 deletions pkg/ddc/alluxio/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ limitations under the License.
package alluxio

import (
"github.com/go-logr/logr"
"reflect"
"testing"

"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/log"

. "github.com/agiledragon/gomonkey"
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
Expand Down Expand Up @@ -268,7 +266,7 @@ func TestInvokeCleanCache(t *testing.T) {
Client: fakeClient,
namespace: testCase.namespace,
name: testCase.name,
Log: logr.New(log.NullLogSink{}),
Log: fake.NullLogger(),
}
err := engine.invokeCleanCache("")
isErr := err != nil
Expand Down
8 changes: 3 additions & 5 deletions pkg/ddc/alluxio/create_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package alluxio

import (
"context"
"github.com/go-logr/logr"
"testing"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
Expand All @@ -27,7 +26,6 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
)

func TestCreateVolume(t *testing.T) {
Expand Down Expand Up @@ -55,7 +53,7 @@ func TestCreateVolume(t *testing.T) {

engine := &AlluxioEngine{
Client: client,
Log: logr.New(log.NullLogSink{}),
Log: fake.NullLogger(),
namespace: "fluid",
name: "hbase",
runtimeInfo: runtimeInfo,
Expand Down Expand Up @@ -118,7 +116,7 @@ func TestCreateFusePersistentVolume(t *testing.T) {

engine := &AlluxioEngine{
Client: client,
Log: logr.New(log.NullLogSink{}),
Log: fake.NullLogger(),
namespace: "fluid",
name: "hbase",
runtimeInfo: runtimeInfo,
Expand Down Expand Up @@ -165,7 +163,7 @@ func TestCreateFusePersistentVolumeClaim(t *testing.T) {

engine := &AlluxioEngine{
Client: client,
Log: logr.New(log.NullLogSink{}),
Log: fake.NullLogger(),
namespace: "fluid",
name: "hbase",
runtimeInfo: runtimeInfo,
Expand Down
8 changes: 3 additions & 5 deletions pkg/ddc/alluxio/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package alluxio

import (
"context"
"github.com/go-logr/logr"
"reflect"
"testing"

Expand All @@ -27,7 +26,6 @@ import (
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
)

func TestUpdateCacheOfDataset(t *testing.T) {
Expand Down Expand Up @@ -70,7 +68,7 @@ func TestUpdateCacheOfDataset(t *testing.T) {

engine := &AlluxioEngine{
Client: client,
Log: logr.New(log.NullLogSink{}),
Log: fake.NullLogger(),
name: "hbase",
namespace: "fluid",
runtime: testRuntimeInputs[0],
Expand Down Expand Up @@ -161,7 +159,7 @@ func TestUpdateDatasetStatus(t *testing.T) {

engine := &AlluxioEngine{
Client: client,
Log: logr.New(log.NullLogSink{}),
Log: fake.NullLogger(),
name: "hbase",
namespace: "fluid",
runtime: testRuntimeInputs[0],
Expand Down Expand Up @@ -294,7 +292,7 @@ func TestBindToDataset(t *testing.T) {

engine := &AlluxioEngine{
Client: client,
Log: logr.New(log.NullLogSink{}),
Log: fake.NullLogger(),
name: "hbase",
namespace: "fluid",
runtime: testRuntimeInputs[0],
Expand Down
Loading

0 comments on commit bf3b453

Please sign in to comment.