func TestCampfire(t *testing.T) {
	util.LogInfo = true
	t.Parallel()

	check := inspeqtor.NewHost()
	action, err := buildCampfireNotifier(check, map[string]string{})
	assert.Nil(t, action)
	assert.NotNil(t, err)

	action, err = buildCampfireNotifier(check, map[string]string{"team": "contribsys", "token": "abcdef123456", "room": "12345"})
	assert.Nil(t, err)
	assert.NotNil(t, action)
	sn := action.(*campfireNotifier)

	var params map[string]string
	var theurl string

	sendHere := func(url, token string, body map[string]map[string]string) error {
		theurl = url
		params = body["message"]
		return nil
	}

	alert := swapEvent(check, inspeqtor.RuleFailed)
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.Equal(t, theurl, "https://contribsys.campfirenow.com/room/12345/speak.json")
	assert.True(t, strings.Index(params["body"], "localhost: swap is greater than than 20%") > -1)

	alert = swapEvent(check, inspeqtor.RuleRecovered)
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["body"], "localhost: swap has recovered.") > -1)

	svc := inspeqtor.NewService("sidekiq")
	alert = &inspeqtor.Event{Type: inspeqtor.ProcessDoesNotExist, Eventable: svc, Rule: nil}
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["body"], "[sidekiq] does not exist.") > -1)

	alert = &inspeqtor.Event{Type: inspeqtor.ProcessExists, Eventable: svc, Rule: nil}
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["body"], "[sidekiq] now running with PID 0") > -1)
}
func TestHipchat(t *testing.T) {
	util.LogInfo = true
	t.Parallel()

	check := inspeqtor.NewHost()
	action, err := buildHipchatNotifier(check, map[string]string{})
	assert.Nil(t, action)
	assert.NotNil(t, err)

	action, err = buildHipchatNotifier(check, map[string]string{"token": "abcdef123456", "room": "12345"})
	assert.Nil(t, err)
	assert.NotNil(t, action)
	sn := action.(*hipchatNotifier)

	var params url.Values
	var theurl string

	sendHere := func(url, token string, body url.Values) error {
		theurl = url
		params = body
		return nil
	}

	alert := swapEvent(check, inspeqtor.RuleFailed)
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.Equal(t, theurl, "https://api.hipchat.com/v1/rooms/message?auth_token=abcdef123456")
	assert.True(t, strings.Index(params["message"][0], "localhost: swap is greater than than 20%") > -1)

	alert = swapEvent(check, inspeqtor.RuleRecovered)
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["message"][0], "localhost: swap has recovered.") > -1)

	svc := inspeqtor.NewService("sidekiq")
	alert = &inspeqtor.Event{Type: inspeqtor.ProcessDoesNotExist, Eventable: svc, Rule: nil}
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["message"][0], "[sidekiq] does not exist.") > -1)

	alert = &inspeqtor.Event{Type: inspeqtor.ProcessExists, Eventable: svc, Rule: nil}
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["message"][0], "[sidekiq] now running with PID 0") > -1)
}
func TestSlack(t *testing.T) {
	util.LogInfo = true
	t.Parallel()

	check := inspeqtor.NewHost()
	action, err := buildSlackNotifier(check, map[string]string{})
	assert.Nil(t, action)
	assert.NotNil(t, err)

	action, err = buildSlackNotifier(check, map[string]string{"team": "contribsys", "url": "https://acmecorp.slack.com/services/hooks/incoming-webhook?token=xxx/xxx/xxx", "icon_emoji": "beer"})
	assert.Nil(t, err)
	assert.NotNil(t, action)
	sn := action.(*slackNotifier)

	var params url.Values
	var theurl string

	sendHere := func(url string, values url.Values) error {
		theurl = url
		params = values
		return nil
	}

	alert := swapEvent(check, inspeqtor.RuleFailed)
	err = sn.triggerSlack(alert, sendHere)
	assert.Nil(t, err)
	assert.Equal(t, "https://acmecorp.slack.com/services/hooks/incoming-webhook?token=xxx/xxx/xxx", theurl)
	assert.True(t, strings.Index(params["payload"][0], "localhost: swap is greater than than 20%") > 0)

	alert = swapEvent(check, inspeqtor.RuleRecovered)
	err = sn.triggerSlack(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["payload"][0], "localhost: swap has recovered.") > 0)

	svc := inspeqtor.NewService("sidekiq")
	alert = &inspeqtor.Event{Type: inspeqtor.ProcessDoesNotExist, Eventable: svc, Rule: nil}
	err = sn.triggerSlack(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["payload"][0], "[sidekiq] does not exist.") > 0)

	alert = &inspeqtor.Event{Type: inspeqtor.ProcessExists, Eventable: svc, Rule: nil}
	err = sn.triggerSlack(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["payload"][0], "[sidekiq] now running with PID 0") > 0)
}