MCPcopy Create free account
hub / github.com/prometheus/common / TestHTTPClientConfig_Marshal

Function TestHTTPClientConfig_Marshal

config/http_config_test.go:2268–2349  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2266}
2267
2268func TestHTTPClientConfig_Marshal(t *testing.T) {
2269 proxyURL, err := url.Parse("http://localhost:8080")
2270 require.NoError(t, err)
2271
2272 t.Run("without HTTP headers", func(t *testing.T) {
2273 config := &HTTPClientConfig{
2274 ProxyConfig: ProxyConfig{
2275 ProxyURL: URL{proxyURL},
2276 },
2277 }
2278
2279 t.Run("YAML", func(t *testing.T) {
2280 actualYAML, err := yaml.Marshal(config)
2281 require.NoError(t, err)
2282 require.YAMLEq(t, `
2283proxy_url: "http://localhost:8080"
2284follow_redirects: false
2285enable_http2: false
2286`, string(actualYAML))
2287
2288 // Unmarshalling the YAML should get the same struct in input.
2289 actual := &HTTPClientConfig{}
2290 require.NoError(t, yaml.Unmarshal(actualYAML, actual))
2291 require.Equal(t, config, actual)
2292 })
2293
2294 t.Run("JSON", func(t *testing.T) {
2295 actualJSON, err := json.Marshal(config)
2296
2297 require.NoError(t, err)
2298 require.JSONEq(t, `{
2299 "proxy_url":"http://localhost:8080",
2300 "tls_config":{"insecure_skip_verify":false},
2301 "follow_redirects":false,
2302 "enable_http2":false
2303 }`, string(actualJSON))
2304
2305 // Unmarshalling the JSON should get the same struct in input.
2306 actual := &HTTPClientConfig{}
2307 require.NoError(t, json.Unmarshal(actualJSON, actual))
2308 require.Equal(t, config, actual)
2309 })
2310 })
2311
2312 t.Run("with HTTP headers", func(t *testing.T) {
2313 config := &HTTPClientConfig{
2314 ProxyConfig: ProxyConfig{
2315 ProxyURL: URL{proxyURL},
2316 },
2317 HTTPHeaders: &Headers{
2318 Headers: map[string]Header{
2319 "X-Test": {
2320 Values: []string{"Value-1", "Value-2"},
2321 },
2322 },
2323 },
2324 }
2325

Callers

nothing calls this directly

Calls 1

EqualMethod · 0.45

Tested by

no test coverage detected