This repository has been archived by the owner on Oct 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
hipchat_test.go
66 lines (55 loc) · 1.69 KB
/
hipchat_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package grim
// Copyright 2015 MediaMath <http://www.mediamath.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import (
"testing"
)
// HC_AUTH_TOKEN="" HC_ROOM_ID="" go test -v -run TestSendMessageToRoomSucceeds
func TestSendMessageToRoomSucceeds(t *testing.T) {
token := getEnvOrSkip(t, "HC_AUTH_TOKEN")
roomID := getEnvOrSkip(t, "HC_ROOM_ID")
from := "Grim"
message := "This is a test message."
color := "random"
err := sendMessageToRoom(token, roomID, from, message, color)
if err != nil {
t.Fatal(err)
}
}
func TestSendMessageToRoomInvalidColor(t *testing.T) {
token := getEnvOrSkip(t, "HC_AUTH_TOKEN")
roomID := getEnvOrSkip(t, "HC_ROOM_ID")
from := "Grim"
message := "This is a test message."
color := "does_not_exist"
err := sendMessageToRoom(token, roomID, from, message, color)
if err != nil {
t.Fatal(err)
}
}
// HC2_AUTH_TOKEN="" HC2_ROOM_ID="" go test -v -run TestSendMessageToRoom2Succeeds
func TestSendMessageToRoom2Succeeds(t *testing.T) {
token := getEnvOrSkip(t, "HC2_AUTH_TOKEN")
roomID := getEnvOrSkip(t, "HC2_ROOM_ID")
from := "Grim"
message := "This is a test message."
color := "random"
err := sendMessageToRoom2(token, roomID, from, message, color)
if err != nil {
t.Fatal(err)
}
}
func TestSanitizeHipchatMessage(t *testing.T) {
type input struct{ message, expected string }
inputs := []input{
{"", ""},
{"\b\f\n\r\t\"\\", `\b\f\n\r\t\"\\`},
{string(make([]byte, 11000)), string(make([]byte, 10000))},
}
for _, i := range inputs {
if o := sanitizeHipchatMessage(i.message); o != i.expected {
t.Errorf("expected %q for %q but got %q", i.expected, i.message, o)
}
}
}