enable managed transport for controller tests
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
This commit is contained in:
parent
5152721ae0
commit
ec45a612b1
|
@ -362,7 +362,7 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
assertConditions: []metav1.Condition{
|
assertConditions: []metav1.Condition{
|
||||||
*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"),
|
*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"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -645,11 +645,10 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
|
||||||
}
|
}
|
||||||
conditions.MarkTrue(obj, sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "foo")
|
conditions.MarkTrue(obj, sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "foo")
|
||||||
},
|
},
|
||||||
want: sreconcile.ResultEmpty,
|
want: sreconcile.ResultEmpty,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
wantRevision: "staging/<commit>",
|
wantRevision: "staging/<commit>",
|
||||||
wantArtifactOutdated: false,
|
wantArtifactOutdated: false,
|
||||||
skipForImplementation: "libgit2",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Optimized clone different ignore",
|
name: "Optimized clone different ignore",
|
||||||
|
@ -670,10 +669,9 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
|
||||||
}
|
}
|
||||||
conditions.MarkTrue(obj, sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "foo")
|
conditions.MarkTrue(obj, sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "foo")
|
||||||
},
|
},
|
||||||
want: sreconcile.ResultSuccess,
|
want: sreconcile.ResultSuccess,
|
||||||
wantRevision: "staging/<commit>",
|
wantRevision: "staging/<commit>",
|
||||||
wantArtifactOutdated: false,
|
wantArtifactOutdated: false,
|
||||||
skipForImplementation: "libgit2",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ import (
|
||||||
"github.com/fluxcd/pkg/runtime/controller"
|
"github.com/fluxcd/pkg/runtime/controller"
|
||||||
"github.com/fluxcd/pkg/runtime/testenv"
|
"github.com/fluxcd/pkg/runtime/testenv"
|
||||||
"github.com/fluxcd/pkg/testserver"
|
"github.com/fluxcd/pkg/testserver"
|
||||||
|
"github.com/go-logr/logr"
|
||||||
"github.com/phayes/freeport"
|
"github.com/phayes/freeport"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/configuration"
|
"github.com/distribution/distribution/v3/configuration"
|
||||||
|
@ -50,6 +51,7 @@ import (
|
||||||
"github.com/fluxcd/source-controller/internal/cache"
|
"github.com/fluxcd/source-controller/internal/cache"
|
||||||
"github.com/fluxcd/source-controller/internal/features"
|
"github.com/fluxcd/source-controller/internal/features"
|
||||||
"github.com/fluxcd/source-controller/internal/helm/registry"
|
"github.com/fluxcd/source-controller/internal/helm/registry"
|
||||||
|
"github.com/fluxcd/source-controller/pkg/git/libgit2/managed"
|
||||||
// +kubebuilder:scaffold:imports
|
// +kubebuilder:scaffold:imports
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -207,6 +209,8 @@ func TestMain(m *testing.M) {
|
||||||
panic(fmt.Sprintf("Failed to create OCI registry client"))
|
panic(fmt.Sprintf("Failed to create OCI registry client"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
managed.InitManagedTransport(logr.Discard())
|
||||||
|
|
||||||
if err := (&GitRepositoryReconciler{
|
if err := (&GitRepositoryReconciler{
|
||||||
Client: testEnv,
|
Client: testEnv,
|
||||||
EventRecorder: record.NewFakeRecorder(32),
|
EventRecorder: record.NewFakeRecorder(32),
|
||||||
|
|
|
@ -222,7 +222,7 @@ func createClientRequest(targetURL string, action git2go.SmartServiceAction,
|
||||||
if len(authOpts.CAFile) > 0 {
|
if len(authOpts.CAFile) > 0 {
|
||||||
certPool := x509.NewCertPool()
|
certPool := x509.NewCertPool()
|
||||||
if ok := certPool.AppendCertsFromPEM(authOpts.CAFile); !ok {
|
if ok := certPool.AppendCertsFromPEM(authOpts.CAFile); !ok {
|
||||||
return nil, nil, fmt.Errorf("failed to use certificate from PEM")
|
return nil, nil, fmt.Errorf("PEM CA bundle could not be appended to x509 certificate pool")
|
||||||
}
|
}
|
||||||
t.TLSClientConfig = &tls.Config{
|
t.TLSClientConfig = &tls.Config{
|
||||||
RootCAs: certPool,
|
RootCAs: certPool,
|
||||||
|
|
|
@ -42,6 +42,10 @@ import (
|
||||||
|
|
||||||
const testRepositoryPath = "../testdata/git/repo"
|
const testRepositoryPath = "../testdata/git/repo"
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
managed.InitManagedTransport(logr.Discard())
|
||||||
|
}
|
||||||
|
|
||||||
// Test_ManagedSSH_KeyTypes assures support for the different
|
// Test_ManagedSSH_KeyTypes assures support for the different
|
||||||
// types of keys for SSH Authentication supported by Flux.
|
// types of keys for SSH Authentication supported by Flux.
|
||||||
func Test_ManagedSSH_KeyTypes(t *testing.T) {
|
func Test_ManagedSSH_KeyTypes(t *testing.T) {
|
||||||
|
@ -124,8 +128,6 @@ func Test_ManagedSSH_KeyTypes(t *testing.T) {
|
||||||
knownHosts, err := ssh.ScanHostKey(u.Host, timeout, git.HostKeyAlgos, false)
|
knownHosts, err := ssh.ScanHostKey(u.Host, timeout, git.HostKeyAlgos, false)
|
||||||
g.Expect(err).ToNot(HaveOccurred())
|
g.Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
managed.InitManagedTransport(logr.Discard())
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
g := NewWithT(t)
|
g := NewWithT(t)
|
||||||
|
@ -223,8 +225,6 @@ func Test_ManagedSSH_KeyExchangeAlgos(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
managed.InitManagedTransport(logr.Discard())
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
g := NewWithT(t)
|
g := NewWithT(t)
|
||||||
|
@ -382,8 +382,6 @@ func Test_ManagedSSH_HostKeyAlgos(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
managed.InitManagedTransport(logr.Discard())
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
g := NewWithT(t)
|
g := NewWithT(t)
|
||||||
|
@ -475,7 +473,6 @@ func Test_ManagedHTTPCheckout(t *testing.T) {
|
||||||
defer server.StopHTTP()
|
defer server.StopHTTP()
|
||||||
|
|
||||||
// Force managed transport to be enabled
|
// Force managed transport to be enabled
|
||||||
managed.InitManagedTransport(logr.Discard())
|
|
||||||
|
|
||||||
repoPath := "test.git"
|
repoPath := "test.git"
|
||||||
err = server.InitRepo("../testdata/git/repo", git.DefaultBranch, repoPath)
|
err = server.InitRepo("../testdata/git/repo", git.DefaultBranch, repoPath)
|
||||||
|
@ -501,7 +498,6 @@ func Test_ManagedHTTPCheckout(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestManagedCheckoutBranch_Checkout(t *testing.T) {
|
func TestManagedCheckoutBranch_Checkout(t *testing.T) {
|
||||||
managed.InitManagedTransport(logr.Discard())
|
|
||||||
g := NewWithT(t)
|
g := NewWithT(t)
|
||||||
|
|
||||||
timeout := 5 * time.Second
|
timeout := 5 * time.Second
|
||||||
|
@ -557,7 +553,6 @@ func TestManagedCheckoutBranch_Checkout(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestManagedCheckoutTag_Checkout(t *testing.T) {
|
func TestManagedCheckoutTag_Checkout(t *testing.T) {
|
||||||
managed.InitManagedTransport(logr.Discard())
|
|
||||||
g := NewWithT(t)
|
g := NewWithT(t)
|
||||||
|
|
||||||
timeout := 5 * time.Second
|
timeout := 5 * time.Second
|
||||||
|
|
Loading…
Reference in New Issue