-
Notifications
You must be signed in to change notification settings - Fork 2
/
room_test.go
72 lines (63 loc) · 1.38 KB
/
room_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
67
68
69
70
71
72
package spark
import (
"os"
"testing"
)
var s *Spark
var allRooms []SparkRoom
// initialize spark client
func getSpark(t *testing.T) *Spark {
token := os.Getenv("SPARK_TOKEN")
if token == "" {
t.Fatal("Please define the SPARK_TOKEN environment variable before running tests")
}
return New(token)
}
func getAllRooms(t *testing.T) {
rooms, err := s.ListRooms(nil)
if err != nil {
t.Error(err)
}
if len(rooms) < 1 {
t.Fatalf("expected at least one room to be listed. Instead got %d\n", len(rooms))
}
allRooms = rooms
}
// test if there are rooms
func TestListRooms(t *testing.T) {
s = getSpark(t)
if len(allRooms) < 1 {
getAllRooms(t)
}
}
// get the first room
func TestGetRoom(t *testing.T) {
s = getSpark(t)
r := allRooms[0].Id
room, err := s.GetRoom(r)
if err != nil {
t.Error(err)
}
if room.Id != r {
t.Error("Expected room ID to be the same")
}
}
func TestGetRoomName(t *testing.T) {
s = getSpark(t)
title := allRooms[0].Title
room, err := s.GetRoomWithName(title)
if err != nil {
t.Error(err)
}
if room.Title != title {
t.Error("Expected the room Name to be the same as what we just got")
}
// expecting this room to be nil
room, err = s.GetRoomWithName("Fizzle Swamp Duck Chocolate")
if err == nil {
t.Error("Rooms that are not found should return an error")
}
if room.Title != "" {
t.Error("Rooms that are not found should be empty")
}
}