<commit_before>package endpoint_test

import (
	"encoding/json"
	"net/http"
	"testing"
	"time"

	"github.com/google/go-cmp/cmp"
	"github.com/influxdata/influxdb/v2"
	"github.com/influxdata/influxdb/v2/mock"
	"github.com/influxdata/influxdb/v2/notification/endpoint"
	influxTesting "github.com/influxdata/influxdb/v2/testing"
)

const (
	id1 = "020f755c3c082000"
	id3 = "020f755c3c082002"
)

var goodBase = endpoint.Base{
	ID:          influxTesting.MustIDBase16Ptr(id1),
	Name:        "name1",
	OrgID:       influxTesting.MustIDBase16Ptr(id3),
	Status:      influxdb.Active,
	Description: "desc1",
}

func TestValidEndpoint(t *testing.T) {
	cases := []struct {
		name string
		src  influxdb.NotificationEndpoint
		err  error
	}{
		{
			name: "invalid endpoint id",
			src:  &endpoint.Slack{},
			err: &influxdb.Error{
				Code: influxdb.EInvalid,
				Msg:  "Notification Endpoint ID is invalid",
			},
		},
		{
			name: "invalid status",
			src: &endpoint.PagerDuty{
				Base: endpoint.Base{
					ID:    influxTesting.MustIDBase16Ptr(id1),
					Name:  "name1",
					OrgID: influxTesting.MustIDBase16Ptr(id3),
				},
			},
			err: &influxdb.Error{
				Code: influxdb.EInvalid,
				Msg:  "invalid status",
			},
		},
		{
			name: "empty name",
			src: &endpoint.Telegram{
				Base: endpoint.Base{
					ID:     influxTesting.MustIDBase16Ptr(id1),
					OrgID:  influxTesting.MustIDBase16Ptr(id3),<commit_msg>feat(notification/telegram): test error on empty endpoint name<commit_after>package endpoint_test

import (
	"encoding/json"
	"net/http"
	"testing"
	"time"

	"github.com/google/go-cmp/cmp"
	"github.com/influxdata/influxdb/v2"
	"github.com/influxdata/influxdb/v2/mock"
	"github.com/influxdata/influxdb/v2/notification/endpoint"
	influxTesting "github.com/influxdata/influxdb/v2/testing"
)

const (
	id1 = "020f755c3c082000"
	id3 = "020f755c3c082002"
)

var goodBase = endpoint.Base{
	ID:          influxTesting.MustIDBase16Ptr(id1),
	Name:        "name1",
	OrgID:       influxTesting.MustIDBase16Ptr(id3),
	Status:      influxdb.Active,
	Description: "desc1",
}

func TestValidEndpoint(t *testing.T) {
	cases := []struct {
		name string
		src  influxdb.NotificationEndpoint
		err  error
	}{
		{
			name: "invalid endpoint id",
			src:  &endpoint.Slack{},
			err: &influxdb.Error{
				Code: influxdb.EInvalid,
				Msg:  "Notification Endpoint ID is invalid",
			},
		},
		{
			name: "invalid status",
			src: &endpoint.PagerDuty{
				Base: endpoint.Base{
					ID:    influxTesting.MustIDBase16Ptr(id1),
					Name:  "name1",
					OrgID: influxTesting.MustIDBase16Ptr(id3),
				},
			},
			err: &influxdb.Error{
				Code: influxdb.EInvalid,
				Msg:  "invalid status",
			},
		},
		{
			name: "empty name PagerDuty",
			src: &endpoint.PagerDuty{
				Base: endpoint.Base{
					ID:     influxTesting.MustIDBase16Ptr(id1),
					OrgID:  influxTesting.MustIDBase16Ptr(id3),
					Status: influxdb.Active,
				},
				ClientURL:  "https://events.pagerduty.com/v2/enqueue",
				RoutingKey: influxdb.SecretField{Key: id1 + "-routing-key"},
			},
			err: &influxdb.Error{
				Code: influxdb.EInvalid,
				Msg:  "Notification Endpoint Name can't be empty",
			},
		},
		{
			name: "empty name Telegram",
			src: &endpoint.Telegram{
				Base: endpoint.Base{
					ID:     influxTesting.MustIDBase16Ptr(id1),
					OrgID:  influxTesting.MustIDBase16Ptr(id3),
{'fraction_non_alphanumeric': 0.1343506882106523, 'fraction_numerical': 0.03411131059245961, 'mean_word_length': 3.3472041612483747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5614041', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1273, 'n_words': 215}