MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / TestGetHttpClient

Function TestGetHttpClient

controllers/workspace/http_test.go:82–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestGetHttpClient(t *testing.T) {
83 t.Run("returns non-nil client", func(t *testing.T) {
84 factory := newTestFactory(t)
85
86 client := factory.GetHttpClient(context.Background(), nil)
87
88 require.NotNil(t, client)
89 })
90
91 t.Run("caches client on repeated calls", func(t *testing.T) {
92 factory := newTestFactory(t)
93
94 client1 := factory.GetHttpClient(context.Background(), nil)
95 client2 := factory.GetHttpClient(context.Background(), nil)
96
97 assert.Same(t, client1, client2)
98 })
99
100 t.Run("rebuilds client when certs changes", func(t *testing.T) {
101 factory := newTestFactory(t,
102 &corev1.ConfigMap{
103 ObjectMeta: metav1.ObjectMeta{
104 Name: "test-certs-1",
105 Namespace: "default",
106 },
107 Data: map[string]string{"ca.crt": generateTestCACert(t)},
108 },
109 &corev1.ConfigMap{
110 ObjectMeta: metav1.ObjectMeta{
111 Name: "test-certs-2",
112 Namespace: "default",
113 },
114 Data: map[string]string{"ca.crt": generateTestCACert(t)},
115 })
116 routingConfig1 := routingConfigWithCerts("test-certs-1", "default")
117 routingConfig2 := routingConfigWithCerts("test-certs-2", "default")
118
119 client1 := factory.GetHttpClient(context.Background(), routingConfig1)
120
121 assert.NotNil(t, client1.Transport.(*http.Transport).TLSClientConfig.RootCAs)
122
123 client2 := factory.GetHttpClient(context.Background(), routingConfig2)
124
125 assert.NotNil(t, client2.Transport.(*http.Transport).TLSClientConfig.RootCAs)
126 assert.NotSame(t, client1, client2)
127
128 client3 := factory.GetHttpClient(context.Background(), nil)
129
130 assert.NotSame(t, client2, client3)
131 assert.Nil(t, client3.Transport.(*http.Transport).TLSClientConfig.RootCAs)
132 })
133
134 t.Run("safe for concurrent access", func(t *testing.T) {
135 factory := newTestFactory(t,
136 &corev1.ConfigMap{
137 ObjectMeta: metav1.ObjectMeta{
138 Name: "test-certs-1",
139 Namespace: "default",

Callers

nothing calls this directly

Calls 4

newTestFactoryFunction · 0.85
generateTestCACertFunction · 0.85
routingConfigWithCertsFunction · 0.85
GetHttpClientMethod · 0.65

Tested by

no test coverage detected