<commit_before>package notifiers

import (
	"testing"

	"github.com/grafana/grafana/pkg/components/simplejson"
	m "github.com/grafana/grafana/pkg/models"
	. "github.com/smartystreets/goconvey/convey"
)

func TestKafkaNotifier(t *testing.T) {
	Convey("Kafka notifier tests", t, func() {

		Convey("Parsing alert notification from settings", func() {
			Convey("empty settings should return error", func() {
				json := `{ }`

				settingsJSON, _ := simplejson.NewJson([]byte(json))
				model := &m.AlertNotification{
					Name:     "kafka_testing",
					Type:     "kafka",
					Settings: settingsJSON,
				}

				_, err := NewKafkaNotifier(model)
				So(err, ShouldNotBeNil)
			})

			Convey("settings should send an event to kafka", func() {
				json := `
				{
					"kafkaEndpoint": "http://localhost:8082",
					"kafkaTopic": "topic1"
				}`

				settingsJSON, _ := simplejson.NewJson([]byte(json))
				model := &m.AlertNotification{
					Name:     "kafka_testing",<commit_msg>Fixed failing go tests<commit_after>package notifiers

import (
	"testing"

	"github.com/grafana/grafana/pkg/components/simplejson"
	m "github.com/grafana/grafana/pkg/models"
	. "github.com/smartystreets/goconvey/convey"
)

func TestKafkaNotifier(t *testing.T) {
	Convey("Kafka notifier tests", t, func() {

		Convey("Parsing alert notification from settings", func() {
			Convey("empty settings should return error", func() {
				json := `{ }`

				settingsJSON, _ := simplejson.NewJson([]byte(json))
				model := &m.AlertNotification{
					Name:     "kafka_testing",
					Type:     "kafka",
					Settings: settingsJSON,
				}

				_, err := NewKafkaNotifier(model)
				So(err, ShouldNotBeNil)
			})

			Convey("settings should send an event to kafka", func() {
				json := `
				{
					"kafkaRestProxy": "http://localhost:8082",
					"kafkaTopic": "topic1"
				}`

				settingsJSON, _ := simplejson.NewJson([]byte(json))
				model := &m.AlertNotification{
					Name:     "kafka_testing",
{'fraction_non_alphanumeric': 0.14735772357723578, 'fraction_numerical': 0.00508130081300813, 'mean_word_length': 3.4547511312217196, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5705041', 'n_tokens_mistral': 807, 'n_tokens_neox': 664, 'n_words': 126}