Fixed app and connection tests.

The tests was not updated.
This commit is contained in:
claudemiro
2015-01-13 13:29:52 -03:00
parent 59457cc734
commit 0e3440bc35
3 changed files with 42 additions and 36 deletions
+35 -27
View File
@@ -5,11 +5,19 @@
package main
import (
"strconv"
"testing"
)
var id = 0
func newApp() App {
return App{Name: "Test", AppID: "123", Key: "123", Secret: "123", OnlySSL: false, ApplicationDisabled: false, UserEvents: true}
a := App{Name: "Test", AppID: strconv.Itoa(id), Key: "123", Secret: "123", OnlySSL: false, ApplicationDisabled: false, UserEvents: true}
a.Init()
id++
return a
}
func Test_add_channels(t *testing.T) {
@@ -18,37 +26,37 @@ func Test_add_channels(t *testing.T) {
// Public
if len(app.PublicChannels) != 0 {
if len(app.PublicChannels()) != 0 {
t.Error("Length of public channels must be 0 before test")
}
app.AddChannel(NewChannel("ID", ""))
app.AddChannel(NewChannel("ID"))
if len(app.PublicChannels) != 1 {
if len(app.PublicChannels()) != 1 {
t.Error("Length os public channels after insert must be 1")
}
// Presence
if len(app.PresenceChannels) != 0 {
if len(app.PresenceChannels()) != 0 {
t.Error("Length of presence channels must be 0 before test")
}
app.AddChannel(NewChannel("presence-test", ""))
app.AddChannel(NewChannel("presence-test"))
if len(app.PresenceChannels) != 1 {
if len(app.PresenceChannels()) != 1 {
t.Error("Length os presence channels after insert must be 1")
}
// Private
if len(app.PrivateChannels) != 0 {
if len(app.PrivateChannels()) != 0 {
t.Error("Length of private channels must be 0 before test")
}
app.AddChannel(NewChannel("private-test", ""))
app.AddChannel(NewChannel("private-test"))
if len(app.PrivateChannels) != 1 {
if len(app.PrivateChannels()) != 1 {
t.Error("Length os private channels after insert must be 1")
}
@@ -56,11 +64,11 @@ func Test_add_channels(t *testing.T) {
func Test_AllChannels(t *testing.T) {
app := newApp()
app.AddChannel(NewChannel("private-test", ""))
app.AddChannel(NewChannel("presence-test", ""))
app.AddChannel(NewChannel("test", ""))
app.AddChannel(NewChannel("private-test"))
app.AddChannel(NewChannel("presence-test"))
app.AddChannel(NewChannel("test"))
if len(app.AllChannels()) != 3 {
if len(app.Channels) != 3 {
t.Error("Must have 3 channels")
}
}
@@ -72,8 +80,8 @@ func Test_New_Subscriber(t *testing.T) {
t.Error("Length of subscribers before test must be 0")
}
conn := NewSubscriber("1", "", nil)
app.AddSubscriber(conn)
conn := NewSubscriber("1", nil)
app.Connect(conn)
if len(app.Subscribers) != 1 {
t.Error("Length os subscribers after test must be 1")
@@ -82,8 +90,8 @@ func Test_New_Subscriber(t *testing.T) {
func Test_find_subscriber(t *testing.T) {
app := newApp()
conn := NewSubscriber("1", "", nil)
app.AddSubscriber(conn)
conn := NewSubscriber("1", nil)
app.Connect(conn)
conn, err := app.FindSubscriber("1")
@@ -112,13 +120,13 @@ func Test_find_or_create_channels(t *testing.T) {
app := newApp()
// Public
if len(app.PublicChannels) != 0 {
if len(app.PublicChannels()) != 0 {
t.Error("Length of public channels must be 0 before test")
}
c := app.FindOrCreateChannelByChannelID("id", "")
c := app.FindOrCreateChannelByChannelID("id")
if len(app.PublicChannels) != 1 {
if len(app.PublicChannels()) != 1 {
t.Error("Length os public channels after insert must be 1")
}
@@ -127,13 +135,13 @@ func Test_find_or_create_channels(t *testing.T) {
}
// Presence
if len(app.PresenceChannels) != 0 {
if len(app.PresenceChannels()) != 0 {
t.Error("Length of presence channels must be 0 before test")
}
c = app.FindOrCreateChannelByChannelID("presence-test", "")
c = app.FindOrCreateChannelByChannelID("presence-test")
if len(app.PresenceChannels) != 1 {
if len(app.PresenceChannels()) != 1 {
t.Error("Length os presence channels after insert must be 1")
}
@@ -142,13 +150,13 @@ func Test_find_or_create_channels(t *testing.T) {
}
// Private
if len(app.PrivateChannels) != 0 {
if len(app.PrivateChannels()) != 0 {
t.Error("Length of private channels must be 0 before test")
}
c = app.FindOrCreateChannelByChannelID("private-test", "")
c = app.FindOrCreateChannelByChannelID("private-test")
if len(app.PrivateChannels) != 1 {
if len(app.PrivateChannels()) != 1 {
t.Error("Length os private channels after insert must be 1")
}
+3 -3
View File
@@ -164,18 +164,18 @@ func NewChannel(channelID string) *Channel {
}
// This function generate a sequencial ID
func newID() string {
func newID() (string, int) {
mutex.Lock()
defer mutex.Unlock()
currentID += 1
return strconv.Itoa(currentID)
return strconv.Itoa(currentID), currentID
}
// Create a new Subscriber
func NewSubscriber(socketID string, s *websocket.Conn) *Subscriber {
id := newID()
id, _ := newID()
log.Infof("Creating a new Subscriber %+v with id %s", socketID, id)
+4 -6
View File
@@ -4,14 +4,12 @@
package main
import (
"testing"
)
import "testing"
func Test_New_ID(t *testing.T) {
id := newID()
_, id := newID()
if newID() != id+1 {
t.Error("Every call to newID must increment the id by one")
if _, i := newID(); i != id+1 {
t.Errorf("Every call to newID must increment the id by one, got: %s", i)
}
}