Skip to content

Commit ec45a61

Browse files
committed
enable managed transport for controller tests
Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent 5152721 commit ec45a61

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

controllers/gitrepository_controller_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
362362
},
363363
wantErr: true,
364364
assertConditions: []metav1.Condition{
365-
*conditions.TrueCondition(sourcev1.FetchFailedCondition, sourcev1.GitOperationFailedReason, "failed to checkout and determine revision: unable to clone '<url>': PEM CA bundle could not be appended to x509 certificate pool"),
365+
*conditions.TrueCondition(sourcev1.FetchFailedCondition, sourcev1.GitOperationFailedReason, "failed to checkout and determine revision: unable to fetch-connect to remote '<url>': PEM CA bundle could not be appended to x509 certificate pool"),
366366
},
367367
},
368368
{
@@ -645,11 +645,10 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
645645
}
646646
conditions.MarkTrue(obj, sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "foo")
647647
},
648-
want: sreconcile.ResultEmpty,
649-
wantErr: true,
650-
wantRevision: "staging/<commit>",
651-
wantArtifactOutdated: false,
652-
skipForImplementation: "libgit2",
648+
want: sreconcile.ResultEmpty,
649+
wantErr: true,
650+
wantRevision: "staging/<commit>",
651+
wantArtifactOutdated: false,
653652
},
654653
{
655654
name: "Optimized clone different ignore",
@@ -670,10 +669,9 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
670669
}
671670
conditions.MarkTrue(obj, sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "foo")
672671
},
673-
want: sreconcile.ResultSuccess,
674-
wantRevision: "staging/<commit>",
675-
wantArtifactOutdated: false,
676-
skipForImplementation: "libgit2",
672+
want: sreconcile.ResultSuccess,
673+
wantRevision: "staging/<commit>",
674+
wantArtifactOutdated: false,
677675
},
678676
}
679677

controllers/suite_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/fluxcd/pkg/runtime/controller"
4040
"github.com/fluxcd/pkg/runtime/testenv"
4141
"github.com/fluxcd/pkg/testserver"
42+
"github.com/go-logr/logr"
4243
"github.com/phayes/freeport"
4344

4445
"github.com/distribution/distribution/v3/configuration"
@@ -50,6 +51,7 @@ import (
5051
"github.com/fluxcd/source-controller/internal/cache"
5152
"github.com/fluxcd/source-controller/internal/features"
5253
"github.com/fluxcd/source-controller/internal/helm/registry"
54+
"github.com/fluxcd/source-controller/pkg/git/libgit2/managed"
5355
// +kubebuilder:scaffold:imports
5456
)
5557

@@ -207,6 +209,8 @@ func TestMain(m *testing.M) {
207209
panic(fmt.Sprintf("Failed to create OCI registry client"))
208210
}
209211

212+
managed.InitManagedTransport(logr.Discard())
213+
210214
if err := (&GitRepositoryReconciler{
211215
Client: testEnv,
212216
EventRecorder: record.NewFakeRecorder(32),

pkg/git/libgit2/managed/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func createClientRequest(targetURL string, action git2go.SmartServiceAction,
222222
if len(authOpts.CAFile) > 0 {
223223
certPool := x509.NewCertPool()
224224
if ok := certPool.AppendCertsFromPEM(authOpts.CAFile); !ok {
225-
return nil, nil, fmt.Errorf("failed to use certificate from PEM")
225+
return nil, nil, fmt.Errorf("PEM CA bundle could not be appended to x509 certificate pool")
226226
}
227227
t.TLSClientConfig = &tls.Config{
228228
RootCAs: certPool,

pkg/git/libgit2/managed_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ import (
4242

4343
const testRepositoryPath = "../testdata/git/repo"
4444

45+
func TestMain(m *testing.M) {
46+
managed.InitManagedTransport(logr.Discard())
47+
}
48+
4549
// Test_ManagedSSH_KeyTypes assures support for the different
4650
// types of keys for SSH Authentication supported by Flux.
4751
func Test_ManagedSSH_KeyTypes(t *testing.T) {
@@ -124,8 +128,6 @@ func Test_ManagedSSH_KeyTypes(t *testing.T) {
124128
knownHosts, err := ssh.ScanHostKey(u.Host, timeout, git.HostKeyAlgos, false)
125129
g.Expect(err).ToNot(HaveOccurred())
126130

127-
managed.InitManagedTransport(logr.Discard())
128-
129131
for _, tt := range tests {
130132
t.Run(tt.name, func(t *testing.T) {
131133
g := NewWithT(t)
@@ -223,8 +225,6 @@ func Test_ManagedSSH_KeyExchangeAlgos(t *testing.T) {
223225
},
224226
}
225227

226-
managed.InitManagedTransport(logr.Discard())
227-
228228
for _, tt := range tests {
229229
t.Run(tt.name, func(t *testing.T) {
230230
g := NewWithT(t)
@@ -382,8 +382,6 @@ func Test_ManagedSSH_HostKeyAlgos(t *testing.T) {
382382
},
383383
}
384384

385-
managed.InitManagedTransport(logr.Discard())
386-
387385
for _, tt := range tests {
388386
t.Run(tt.name, func(t *testing.T) {
389387
g := NewWithT(t)
@@ -475,7 +473,6 @@ func Test_ManagedHTTPCheckout(t *testing.T) {
475473
defer server.StopHTTP()
476474

477475
// Force managed transport to be enabled
478-
managed.InitManagedTransport(logr.Discard())
479476

480477
repoPath := "test.git"
481478
err = server.InitRepo("../testdata/git/repo", git.DefaultBranch, repoPath)
@@ -501,7 +498,6 @@ func Test_ManagedHTTPCheckout(t *testing.T) {
501498
}
502499

503500
func TestManagedCheckoutBranch_Checkout(t *testing.T) {
504-
managed.InitManagedTransport(logr.Discard())
505501
g := NewWithT(t)
506502

507503
timeout := 5 * time.Second
@@ -557,7 +553,6 @@ func TestManagedCheckoutBranch_Checkout(t *testing.T) {
557553
}
558554

559555
func TestManagedCheckoutTag_Checkout(t *testing.T) {
560-
managed.InitManagedTransport(logr.Discard())
561556
g := NewWithT(t)
562557

563558
timeout := 5 * time.Second

0 commit comments

Comments
 (0)