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

Function TestNewClientFromInvalidConfig

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

Source from the content-addressed store, hash-verified

555}
556
557func TestNewClientFromInvalidConfig(t *testing.T) {
558 newClientInvalidConfig := []struct {
559 clientConfig HTTPClientConfig
560 errorMsg string
561 }{
562 {
563 clientConfig: HTTPClientConfig{
564 TLSConfig: TLSConfig{
565 CAFile: MissingCA,
566 InsecureSkipVerify: true,
567 },
568 },
569 errorMsg: fmt.Sprintf("unable to load specified CA cert %s:", MissingCA),
570 },
571 {
572 clientConfig: HTTPClientConfig{
573 TLSConfig: TLSConfig{
574 CAFile: InvalidCA,
575 InsecureSkipVerify: true,
576 },
577 },
578 errorMsg: fmt.Sprintf("unable to use specified CA cert %s", InvalidCA),
579 },
580 }
581
582 for _, invalidConfig := range newClientInvalidConfig {
583 client, err := NewClientFromConfig(invalidConfig.clientConfig, "test")
584 if client != nil {
585 t.Errorf("A client instance was returned instead of nil using this config: %+v", invalidConfig.clientConfig)
586 }
587 if err == nil {
588 t.Errorf("No error was returned using this config: %+v", invalidConfig.clientConfig)
589 }
590 if !strings.Contains(err.Error(), invalidConfig.errorMsg) {
591 t.Errorf("Expected error %q does not contain %q", err.Error(), invalidConfig.errorMsg)
592 }
593 }
594}
595
596func TestCustomDialContextFunc(t *testing.T) {
597 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