kafka_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package notifiers
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. m "github.com/grafana/grafana/pkg/models"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestKafkaNotifier(t *testing.T) {
  9. Convey("Kafka notifier tests", t, func() {
  10. Convey("Parsing alert notification from settings", func() {
  11. Convey("empty settings should return error", func() {
  12. json := `{ }`
  13. settingsJSON, _ := simplejson.NewJson([]byte(json))
  14. model := &m.AlertNotification{
  15. Name: "kafka_testing",
  16. Type: "kafka",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewKafkaNotifier(model)
  20. So(err, ShouldNotBeNil)
  21. })
  22. Convey("settings should send an event to kafka", func() {
  23. json := `
  24. {
  25. "kafkaRestProxy": "http://localhost:8082",
  26. "kafkaTopic": "topic1"
  27. }`
  28. settingsJSON, _ := simplejson.NewJson([]byte(json))
  29. model := &m.AlertNotification{
  30. Name: "kafka_testing",
  31. Type: "kafka",
  32. Settings: settingsJSON,
  33. }
  34. not, err := NewKafkaNotifier(model)
  35. kafkaNotifier := not.(*KafkaNotifier)
  36. So(err, ShouldBeNil)
  37. So(kafkaNotifier.Name, ShouldEqual, "kafka_testing")
  38. So(kafkaNotifier.Type, ShouldEqual, "kafka")
  39. So(kafkaNotifier.Endpoint, ShouldEqual, "http://localhost:8082")
  40. So(kafkaNotifier.Topic, ShouldEqual, "topic1")
  41. })
  42. })
  43. })
  44. }