Skip to content

Commit 4ef5096

Browse files
author
Per G. da Silva
committed
fix server unit test
Signed-off-by: Per G. da Silva <pegoncal@redhat.com>
1 parent 91983d7 commit 4ef5096

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

pkg/lib/controller-runtime/client/fake_ssa.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ func (c fakeStatusWriter) Patch(ctx context.Context, obj k8scontrollerclient.Obj
4444
subResourceOpts := make([]k8scontrollerclient.SubResourcePatchOption, 0, len(opts))
4545
for _, opt := range opts {
4646
// Skip ForceOwnership options by checking if they would apply it
47-
if subOpt, ok := opt.(interface{ ApplyToPatch(*k8scontrollerclient.PatchOptions) }); ok {
47+
if subOpt, ok := opt.(interface {
48+
ApplyToPatch(*k8scontrollerclient.PatchOptions)
49+
}); ok {
4850
testOpts := &k8scontrollerclient.PatchOptions{}
4951
subOpt.ApplyToPatch(testOpts)
5052
// If Force is set, this is ForceOwnership, skip it

pkg/lib/server/server_test.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/sirupsen/logrus"
2020
"github.com/stretchr/testify/assert"
2121
"github.com/stretchr/testify/require"
22+
utilnet "k8s.io/apimachinery/pkg/util/net"
2223
"k8s.io/client-go/rest"
2324
)
2425

@@ -243,13 +244,13 @@ func TestHTTPClientHasTLSConfig(t *testing.T) {
243244
// Verify that the client has a transport configured
244245
require.NotNil(t, httpClient.Transport, "HTTP client transport should be configured")
245246

246-
// Check if it's an http.Transport with TLS config
247-
transport, ok := httpClient.Transport.(*http.Transport)
248-
require.True(t, ok, "Transport should be *http.Transport")
249-
require.NotNil(t, transport.TLSClientConfig, "TLS config should be set")
247+
// Extract TLS config, unwrapping any transport wrappers (e.g. trackedTransport)
248+
tlsConfig, err := utilnet.TLSClientConfig(httpClient.Transport)
249+
require.NoError(t, err, "Should be able to extract TLS config from transport")
250+
require.NotNil(t, tlsConfig, "TLS config should be set")
250251

251252
// Verify that RootCAs is configured (this proves CA cert is loaded)
252-
assert.NotNil(t, transport.TLSClientConfig.RootCAs, "RootCAs should be configured from kubeConfig")
253+
assert.NotNil(t, tlsConfig.RootCAs, "RootCAs should be configured from kubeConfig")
253254

254255
// Verify timeout is set
255256
assert.Equal(t, 30*time.Second, httpClient.Timeout, "Timeout should match kubeConfig")
@@ -519,20 +520,13 @@ func TestRootCAsConfiguration(t *testing.T) {
519520
client, err := rest.HTTPClientFor(config)
520521
require.NoError(t, err)
521522

522-
// Verify transport has TLS config
523-
transport, ok := client.Transport.(*http.Transport)
524-
require.True(t, ok)
525-
require.NotNil(t, transport.TLSClientConfig)
523+
// Extract TLS config, unwrapping any transport wrappers (e.g. trackedTransport)
524+
tlsConfig, err := utilnet.TLSClientConfig(client.Transport)
525+
require.NoError(t, err, "Should be able to extract TLS config from transport")
526+
require.NotNil(t, tlsConfig, "TLS config should be set")
526527

527528
// The RootCAs should be configured
528-
if transport.TLSClientConfig.RootCAs != nil {
529-
// Success - RootCAs are configured
530-
assert.NotNil(t, transport.TLSClientConfig.RootCAs)
531-
} else {
532-
// On some systems, if CAData is invalid, RootCAs might be nil
533-
// but the important thing is no error was returned
534-
t.Log("RootCAs is nil - this might be due to invalid test certificate")
535-
}
529+
assert.NotNil(t, tlsConfig.RootCAs, "RootCAs should be configured from kubeConfig CA data")
536530
}
537531

538532
// TestHTTPClientTimeout verifies timeout configuration

0 commit comments

Comments
 (0)