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

Function TestNewClientFromInvalidConfig

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

Source from the content-addressed store, hash-verified

596}
597
598func TestNewClientFromInvalidConfig(t *testing.T) {
599 newClientInvalidConfig := []struct {
600 clientConfig HTTPClientConfig
601 errorMsg string
602 }{
603 {
604 clientConfig: HTTPClientConfig{
605 TLSConfig: TLSConfig{
606 CAFile: MissingCA,
607 InsecureSkipVerify: true,
608 },
609 },
610 errorMsg: "unable to read CA cert: unable to read file " + MissingCA,
611 },
612 {
613 clientConfig: HTTPClientConfig{
614 TLSConfig: TLSConfig{
615 CAFile: InvalidCA,
616 InsecureSkipVerify: true,
617 },
618 },
619 errorMsg: "unable to use specified CA cert file " + InvalidCA,
620 },
621 }
622
623 for _, invalidConfig := range newClientInvalidConfig {
624 client, err := NewClientFromConfig(invalidConfig.clientConfig, "test")
625 if client != nil {
626 t.Errorf("A client instance was returned instead of nil using this config: %+v", invalidConfig.clientConfig)
627 }
628 if err == nil {
629 t.Errorf("No error was returned using this config: %+v", invalidConfig.clientConfig)
630 }
631 if !strings.Contains(err.Error(), invalidConfig.errorMsg) {
632 t.Errorf("Expected error %q does not contain %q", err.Error(), invalidConfig.errorMsg)
633 }
634 }
635}
636
637func TestCustomDialContextFunc(t *testing.T) {
638 dialFn := func(_ context.Context, _, _ string) (net.Conn, error) {

Callers

nothing calls this directly

Calls 2

NewClientFromConfigFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…