notifytest

package
v0.0.0-release-12.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: AGPL-3.0 Imports: 75 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WithBasicAuth             = MimirIntegrationHTTPConfigOption("basic_auth")
	WithLegacyBearerTokenAuth = MimirIntegrationHTTPConfigOption("bearer_token")
	WithAuthorization         = MimirIntegrationHTTPConfigOption("authorization")
	WithOAuth2                = MimirIntegrationHTTPConfigOption("oauth2")
	WithTLS                   = MimirIntegrationHTTPConfigOption("tls_config")
	WithHeaders               = MimirIntegrationHTTPConfigOption("headers")
	WithProxy                 = MimirIntegrationHTTPConfigOption("proxy_config")
	WithDefault               = MimirIntegrationHTTPConfigOption("default")
)

Variables

View Source
var AllKnownV1ConfigsForTesting = map[schema.IntegrationType]NotifierConfigTest{
	alertmanager.Type: {
		NotifierType:                alertmanager.Type,
		Version:                     schema.V1,
		Config:                      alertmanagerv1.FullValidConfigForTesting,
		Secrets:                     alertmanagerv1.FullValidSecretsForTesting,
		CommonHTTPConfigUnsupported: true,
	},
	dingding.Type: {
		NotifierType: dingding.Type,
		Version:      schema.V1,
		Config:       dingdingv1.FullValidConfigForTesting,
	},
	discord.Type: {
		NotifierType: discord.Type,
		Version:      schema.V1,
		Config:       discordv1.FullValidConfigForTesting,
	},
	email.Type: {
		NotifierType:                email.Type,
		Version:                     schema.V1,
		Config:                      emailv1.FullValidConfigForTesting,
		CommonHTTPConfigUnsupported: true,
	},
	googlechat.Type: {
		NotifierType: googlechat.Type,
		Version:      schema.V1,
		Config:       googlechatv1.FullValidConfigForTesting,
		Secrets:      googlechatv1.FullValidSecretsForTesting,
	},
	jira.Type: {
		NotifierType: jira.Type,
		Version:      schema.V1,
		Config:       jirav1.FullValidConfigForTesting,
		Secrets:      jirav1.FullValidSecretsForTesting,
	},
	kafka.Type: {
		NotifierType: kafka.Type,
		Version:      schema.V1,
		Config:       kafkav1.FullValidConfigForTesting,
		Secrets:      kafkav1.FullValidSecretsForTesting,
	},
	line.Type: {
		NotifierType: line.Type,
		Version:      schema.V1,
		Config:       linev1.FullValidConfigForTesting,
		Secrets:      linev1.FullValidSecretsForTesting,
	},
	mqtt.Type: {
		NotifierType:                mqtt.Type,
		Version:                     schema.V1,
		Config:                      mqttv1.FullValidConfigForTesting,
		Secrets:                     mqttv1.FullValidSecretsForTesting,
		CommonHTTPConfigUnsupported: true,
	},
	oncall.Type: {
		NotifierType: oncall.Type,
		Version:      schema.V1,
		Config:       oncallv1.FullValidConfigForTesting,
		Secrets:      oncallv1.FullValidSecretsForTesting,
	},
	opsgenie.Type: {
		NotifierType: opsgenie.Type,
		Version:      schema.V1,
		Config:       opsgeniev1.FullValidConfigForTesting,
		Secrets:      opsgeniev1.FullValidSecretsForTesting,
	},
	pagerduty.Type: {
		NotifierType: pagerduty.Type,
		Version:      schema.V1,
		Config:       pagerdutyv1.FullValidConfigForTesting,
		Secrets:      pagerdutyv1.FullValidSecretsForTesting,
	},
	pushover.Type: {
		NotifierType: pushover.Type,
		Version:      schema.V1,
		Config:       pushoverv1.FullValidConfigForTesting,
		Secrets:      pushoverv1.FullValidSecretsForTesting,
	},
	sensugo.Type: {
		NotifierType: sensugo.Type,
		Version:      schema.V1,
		Config:       sensugov1.FullValidConfigForTesting,
		Secrets:      sensugov1.FullValidSecretsForTesting,
	},
	slack.Type: {
		NotifierType:                slack.Type,
		Version:                     schema.V1,
		Config:                      slackv1.FullValidConfigForTesting,
		Secrets:                     slackv1.FullValidSecretsForTesting,
		CommonHTTPConfigUnsupported: true,
	},
	sns.Type: {
		NotifierType:                sns.Type,
		Version:                     schema.V1,
		Config:                      snsv1.FullValidConfigForTesting,
		CommonHTTPConfigUnsupported: true,
	},
	teams.Type: {
		NotifierType: teams.Type,
		Version:      schema.V1,
		Config:       teamsv1.FullValidConfigForTesting,
	},
	telegram.Type: {
		NotifierType: telegram.Type,
		Version:      schema.V1,
		Config:       telegramv1.FullValidConfigForTesting,
		Secrets:      telegramv1.FullValidSecretsForTesting,
	},
	threema.Type: {
		NotifierType: threema.Type,
		Version:      schema.V1,
		Config:       threemav1.FullValidConfigForTesting,
		Secrets:      threemav1.FullValidSecretsForTesting,
	},
	victorops.Type: {
		NotifierType: victorops.Type,
		Version:      schema.V1,
		Config:       victoropsv1.FullValidConfigForTesting,
		Secrets:      victoropsv1.FullValidSecretsForTesting,
	},
	webhook.Type: {
		NotifierType: webhook.Type,
		Version:      schema.V1,
		Config:       webhookv1.FullValidConfigForTesting,
		Secrets:      webhookv1.FullValidSecretsForTesting,
	},
	wecom.Type: {
		NotifierType: wecom.Type,
		Version:      schema.V1,
		Config:       wecomv1.FullValidConfigForTesting,
		Secrets:      wecomv1.FullValidSecretsForTesting,
	},
	webex.Type: {
		NotifierType: webex.Type,
		Version:      schema.V1,
		Config:       webexv1.FullValidConfigForTesting,
		Secrets:      webexv1.FullValidSecretsForTesting,
	},
}
View Source
var FullValidHTTPConfigForTesting = fmt.Sprintf(`{
	"http_config": {
		"oauth2": {
			"client_id": "test-client-id",
			"client_secret": "test-client-secret",
			"token_url": "https://localhost/auth/token",
			"scopes": ["scope1", "scope2"],
			"endpoint_params": {
				"param1": "value1",
				"param2": "value2"
			},
			"tls_config": {
				"insecureSkipVerify": false,
				"clientCertificate": %[1]q,
				"clientKey": %[2]q,
				"caCertificate": %[3]q
			},
			"proxy_config": {
				"proxy_url": "http://localproxy:8080",
				"no_proxy": "localhost",
				"proxy_from_environment": false,
				"proxy_connect_header": {
					"X-Proxy-Header": "proxy-value"
				}
			}
		}
    }
}`, http.TestCertPem, http.TestKeyPem, http.TestCACert)
View Source
var FullValidHTTPConfigSecretsForTesting = fmt.Sprintf(`{
	"http_config.oauth2.client_secret": "test-override-oauth2-secret",
	"http_config.oauth2.tls_config.clientCertificate": %[1]q,
	"http_config.oauth2.tls_config.clientKey": %[2]q,
	"http_config.oauth2.tls_config.caCertificate": %[3]q
}`, http.TestCertPem, http.TestKeyPem, http.TestCACert)
View Source
var ValidMimirHTTPConfigs = map[MimirIntegrationHTTPConfigOption]string{
	WithBasicAuth: `{
		"http_config": {
			"tls_config": {
				"insecure_skip_verify": false
			},
			"follow_redirects": true,
			"enable_http2": true,
			"proxy_url": "",
			"basic_auth": {
				"username": "test-username",
				"password": "test-password"
			}
		}
	}`,
	WithLegacyBearerTokenAuth: `{
		"http_config": {
			"tls_config": {
				"insecure_skip_verify": false
			},
			"follow_redirects": true,
			"enable_http2": true,
			"proxy_url": "",
			"bearer_token": "test-token"
		}
	}`,
	WithAuthorization: `{
		"http_config": {
			"tls_config": {
				"insecure_skip_verify": false
			},
			"follow_redirects": true,
			"enable_http2": true,
			"proxy_url": "",
			"authorization": {
				"type": "bearer",
				"credentials": "test-credentials"
			}
		}
	}`,
	WithOAuth2: `{
		"http_config": {
			"tls_config": {
				"insecure_skip_verify": false
			},
			"follow_redirects": true,
			"enable_http2": true,
			"proxy_url": "",
			"oauth2": {
				"client_id": "test-client-id",
				"client_secret": "test-client-secret",
				"client_secret_file": "",
				"client_secret_ref": "",
				"token_url": "https://localhost/auth/token",
				"scopes": ["scope1", "scope2"],
				"endpoint_params": {
					"param1": "value1",
					"param2": "value2"
				},
				"TLSConfig": {
                    "insecure_skip_verify": false
				},
				"proxy_url": ""
			}
	    }
	}`,
	WithTLS: `{
		"http_config": {
			"follow_redirects": true,
			"enable_http2": true,
			"proxy_url": "",
			"tls_config": {
				"insecure_skip_verify": false,
				"server_name": "test-server-name"
			}
	    }
	}`,
	WithHeaders: `{
		"http_config": {
			"tls_config": {
				"insecure_skip_verify": false
			},
			"follow_redirects": true,
			"enable_http2": true,
			"http_headers": {
				"headers": {
					"X-Header-1": {
						"secrets": ["value1"]
					},
					"X-Header-2": {
						"values": ["value2"]
					}
				}
			}
		}
	}`,
	WithProxy: `{
		"http_config": {
			"tls_config": {
				"insecure_skip_verify": false
			},
			"follow_redirects": true,
			"enable_http2": true,
			"proxy_url": "http://localproxy:8080",
			"no_proxy": "localhost",
			"proxy_connect_header": {
				"X-Proxy-Header": ["proxy-value"]
			}
		}
	}`,

	WithDefault: `{
		"http_config": {
			"tls_config": {
				"insecure_skip_verify": false
			},
			"follow_redirects": true,
			"enable_http2": true,
			"proxy_url": ""
		}
	}`,
}

Functions

func ForEachIntegrationType

func ForEachIntegrationType(t *testing.T, f func(configType reflect.Type))

ForEachIntegrationTypeReceiver runs the given function for each integration type.

func ForEachIntegrationTypeReceiver

func ForEachIntegrationTypeReceiver(t *testing.T, f func(configType reflect.Type, receiver promCfg.Receiver, rawConfig string))

ForEachIntegrationTypeReceiver runs the given function for each integration type.

func GetMimirIntegration

func GetMimirIntegration[T any](opts ...MimirIntegrationHTTPConfigOption) (T, error)

GetMimirIntegration creates a new instance of the given integration type with selected http config options. It panics if the configuration process encounters an issue.

func GetMimirIntegrationForType

func GetMimirIntegrationForType(iType reflect.Type, opts ...MimirIntegrationHTTPConfigOption) (any, error)

GetMimirIntegrationForType creates a new instance of the given integration type with selected http config options. It panics if the configuration process encounters an issue.

func GetMimirReceiverWithAllIntegrations

func GetMimirReceiverWithAllIntegrations(opts ...MimirIntegrationHTTPConfigOption) (promCfg.Receiver, error)

GetMimirReceiverWithAllIntegrations creates a Receiver with all integrations configured from given types and options. It returns a Receiver for testing purposes or an error if the configuration process encounters an issue.

func GetMimirReceiverWithIntegrations

func GetMimirReceiverWithIntegrations(iTypes []reflect.Type, opts ...MimirIntegrationHTTPConfigOption) (promCfg.Receiver, error)

GetMimirReceiverWithIntegrations creates a Receiver with selected integrations configured from given types and options. It returns a Receiver for testing purposes or an error if the configuration process encounters an issue.

func GetRawConfigForMimirIntegration

func GetRawConfigForMimirIntegration(iType reflect.Type, opts ...MimirIntegrationHTTPConfigOption) (string, error)

Types

type MimirIntegrationHTTPConfigOption

type MimirIntegrationHTTPConfigOption string

type NotifierConfigTest

type NotifierConfigTest struct {
	NotifierType                schema.IntegrationType
	Version                     schema.Version
	Config                      string
	Secrets                     string
	CommonHTTPConfigUnsupported bool
}

func (NotifierConfigTest) GetRawNotifierConfig

func (n NotifierConfigTest) GetRawNotifierConfig(name string) *models.IntegrationConfig

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL