Skip to content

Commit

Permalink
Add unit test case for flux/git-repository-controller (#771)
Browse files Browse the repository at this point in the history
Signed-off-by: chengleqi <leqicheng@stu.xidian.edu.cn>
  • Loading branch information
chengleqi authored Aug 8, 2022
1 parent e895d84 commit 98cfc88
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions controllers/fluxcd/git-repository-controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ package fluxcd

import (
"context"
"fmt"
"github.com/go-logr/logr"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"kubesphere.io/devops/controllers/core"
"kubesphere.io/devops/pkg/api/devops/v1alpha3"
"kubesphere.io/devops/pkg/api/gitops/v1alpha1"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -321,3 +324,42 @@ func TestGitRepositoryReconciler_GetName(t *testing.T) {
assert.Equal(t, "FluxGitRepositoryReconciler", r.GetName())
})
}

func TestGitRepositoryReconciler_SetupWithManager(t *testing.T) {
schema, err := v1alpha3.SchemeBuilder.Register().Build()
assert.Nil(t, err)

type fields struct {
Client client.Client
log logr.Logger
recorder record.EventRecorder
}
type args struct {
mgr ctrl.Manager
}
tests := []struct {
name string
fields fields
args args
wantErr assert.ErrorAssertionFunc
}{{
name: "normal",
args: args{
mgr: &core.FakeManager{
Client: fake.NewFakeClientWithScheme(schema),
Scheme: schema,
},
},
wantErr: core.NoErrors,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := &GitRepositoryReconciler{
Client: tt.fields.Client,
log: tt.fields.log,
recorder: tt.fields.recorder,
}
tt.wantErr(t, r.SetupWithManager(tt.args.mgr), fmt.Sprintf("SetupWithManager(%v)", tt.args.mgr))
})
}
}

0 comments on commit 98cfc88

Please sign in to comment.