Standardized error messages

This commit is contained in:
claudemiro
2016-03-06 18:12:03 -03:00
parent a7c5813501
commit e71294de18
3 changed files with 46 additions and 46 deletions
+31 -31
View File
@@ -25,7 +25,7 @@ func TestConnect(t *testing.T) {
app.Connect(newConnection("socketID", nil))
if len(app.Connections) != 1 {
t.Errorf("Connections must be 1, but was %d", len(app.Connections))
t.Errorf("len(app.Connections) == %d, wants %d", len(app.Connections), 1)
}
}
@@ -37,7 +37,7 @@ func TestDisconnect(t *testing.T) {
app.Disconnect("socketID")
if len(app.Connections) != 0 {
t.Errorf("Connections must be 0, but was %d", len(app.Connections))
t.Errorf("len(app.Connections) == %d, wants %d", len(app.Connections), 0)
}
}
@@ -48,11 +48,11 @@ func TestFindConnection(t *testing.T) {
app.Connect(newConnection("socketID", nil))
if _, err := app.FindConnection("socketID"); err != nil {
t.Error("Must find Connection")
t.Errorf("app.FindConnection('socketID') == _, %q, wants %v", err, nil)
}
if _, err := app.FindConnection("NotFound"); err == nil {
t.Error("Must not found Connection")
t.Errorf("app.FindConnection('socketID') == _, %q, wants !nil", err)
}
}
@@ -64,7 +64,7 @@ func TestFindChannelByChannelID(t *testing.T) {
app.AddChannel(channel)
if _, err := app.FindChannelByChannelID("ID"); err != nil {
t.Error("Channel not found")
t.Errorf("app.FindChannelByChannelID('ID') == _, %q, wants %v", err, nil)
}
}
@@ -72,13 +72,13 @@ func TestFindOrCreateChannelByChannelID(t *testing.T) {
app := newTestApp()
if len(app.Channels) != 0 {
t.Error("Length of channels must be 0 before test")
t.Errorf("len(app.Channels) == %d, wants %d", len(app.Channels), 0)
}
app.FindOrCreateChannelByChannelID("ID")
if len(app.Channels) != 1 {
t.Error("Length of channels must be 1 after test")
t.Errorf("len(app.Channels) == %d, wants %d", len(app.Channels), 1)
}
}
@@ -87,20 +87,20 @@ func TestRemoveChannel(t *testing.T) {
app := newTestApp()
if len(app.Channels) != 0 {
t.Error("Length of channels must be 0 before test")
t.Errorf("len(app.Channels) == %d, wants %d", len(app.Channels), 0)
}
channel := newChannel("ID")
app.AddChannel(channel)
if len(app.Channels) != 1 {
t.Error("Length of channels after insert must be 1")
t.Errorf("len(app.Channels) == %d, wants %d", len(app.Channels), 1)
}
app.RemoveChannel(channel)
if len(app.Channels) != 0 {
t.Error("Length of channels must be 0 after remove")
t.Errorf("len(app.Channels) == %d, wants %d", len(app.Channels), 0)
}
}
@@ -112,37 +112,37 @@ func Test_add_channels(t *testing.T) {
// Public
if len(app.PublicChannels()) != 0 {
t.Error("Length of public channels must be 0 before test")
t.Errorf("len(app.PublicChannels()) == %d, wants %d", len(app.PublicChannels()), 0)
}
app.AddChannel(newChannel("ID"))
if len(app.PublicChannels()) != 1 {
t.Error("Length os public channels after insert must be 1")
t.Errorf("len(app.PublicChannels()) == %d, wants %d", len(app.PublicChannels()), 1)
}
// Presence
if len(app.PresenceChannels()) != 0 {
t.Error("Length of presence channels must be 0 before test")
t.Errorf("len(app.PresenceChannels()) == %d, wants %d", len(app.PresenceChannels()), 0)
}
app.AddChannel(newChannel("presence-test"))
if len(app.PresenceChannels()) != 1 {
t.Error("Length os presence channels after insert must be 1")
t.Errorf("len(app.PresenceChannels()) == %d, wants %d", len(app.PresenceChannels()), 1)
}
// Private
if len(app.PrivateChannels()) != 0 {
t.Error("Length of private channels must be 0 before test")
t.Errorf("len(app.PrivateChannels()) == %d, wants %d", len(app.PrivateChannels()), 0)
}
app.AddChannel(newChannel("private-test"))
if len(app.PrivateChannels()) != 1 {
t.Error("Length os private channels after insert must be 1")
t.Errorf("len(app.PrivateChannels()) == %d, wants %d", len(app.PrivateChannels()), 1)
}
}
@@ -154,7 +154,7 @@ func Test_AllChannels(t *testing.T) {
app.AddChannel(newChannel("test"))
if len(app.Channels) != 3 {
t.Error("Must have 3 channels")
t.Errorf("len(app.Channels) == %d, wants %d", len(app.Channels), 3)
}
}
@@ -162,14 +162,14 @@ func Test_New_Subscriber(t *testing.T) {
app := newTestApp()
if len(app.Connections) != 0 {
t.Error("Length of subscribers before test must be 0")
t.Errorf("len(app.Connections) == %d, wants %d", len(app.Connections), 0)
}
conn := newConnection("1", nil)
app.Connect(conn)
if len(app.Connections) != 1 {
t.Error("Length os subscribers after test must be 1")
t.Errorf("len(app.Connections) == %d, wants %d", len(app.Connections), 1)
}
}
@@ -185,7 +185,7 @@ func Test_find_subscriber(t *testing.T) {
}
if conn.SocketID != "1" {
t.Error("Wrong subscriber.")
t.Errorf("conn.SocketID == %s, wants %s", conn.SocketID, "1")
}
// Find a wrong subscriber
@@ -193,11 +193,11 @@ func Test_find_subscriber(t *testing.T) {
conn, err = app.FindConnection("DoesNotExists")
if err == nil {
t.Error("Opps, Must be nil")
t.Errorf("err == %q, wants !nil", err)
}
if conn != nil {
t.Error("Opps, Must be nil")
t.Errorf("conn == %q, wants nil", conn)
}
}
@@ -206,47 +206,47 @@ func Test_find_or_create_channels(t *testing.T) {
// Public
if len(app.PublicChannels()) != 0 {
t.Error("Length of public channels must be 0 before test")
t.Errorf("len(app.PublicChannels()) == %d, wants %d", len(app.PublicChannels()), 0)
}
c := app.FindOrCreateChannelByChannelID("id")
if len(app.PublicChannels()) != 1 {
t.Error("Length os public channels after insert must be 1")
t.Errorf("len(app.PublicChannels()) == %d, wants %d", len(app.PublicChannels()), 1)
}
if c.ChannelID != "id" {
t.Error("Opps wrong channel")
t.Errorf("c.ChannelID == %s, wants %s", c.ChannelID, "id")
}
// Presence
if len(app.PresenceChannels()) != 0 {
t.Error("Length of presence channels must be 0 before test")
t.Errorf("len(app.PresenceChannels()) == %d, wants %d", len(app.PresenceChannels()), 0)
}
c = app.FindOrCreateChannelByChannelID("presence-test")
if len(app.PresenceChannels()) != 1 {
t.Error("Length os presence channels after insert must be 1")
t.Errorf("len(app.PresenceChannels()) == %d, wants %d", len(app.PresenceChannels()), 1)
}
if c.ChannelID != "presence-test" {
t.Error("Opps wrong channel")
t.Errorf("c.ChannelID == %s, wants %s", c.ChannelID, "presence-test")
}
// Private
if len(app.PrivateChannels()) != 0 {
t.Error("Length of private channels must be 0 before test")
t.Errorf("len(app.PrivateChannels()) == %d, wants %d", len(app.PrivateChannels()), 0)
}
c = app.FindOrCreateChannelByChannelID("private-test")
if len(app.PrivateChannels()) != 1 {
t.Error("Length os private channels after insert must be 1")
t.Errorf("len(app.PrivateChannels()) == %d, wants %d", len(app.PrivateChannels()), 1)
}
if c.ChannelID != "private-test" {
t.Error("Opps wrong channel")
t.Errorf("c.ChannelID == %s, wants %s", c.ChannelID, "private-test")
}
}
+12 -12
View File
@@ -10,13 +10,13 @@ func TestIsOccupied(t *testing.T) {
c := newChannel("ID")
if c.IsOccupied() {
t.Error("Channels must be empty")
t.Errorf("c.IsOccupied() == %t, wants %t", c.IsOccupied(), false)
}
c.Subscriptions["ID"] = newSubscription(newConnection("ID", nil), "")
if !c.IsOccupied() {
t.Error("Channels must be empty")
t.Errorf("c.IsOccupied() == %t, wants %t", c.IsOccupied(), true)
}
}
@@ -24,7 +24,7 @@ func TestIsPrivate(t *testing.T) {
c := newChannel("private-channel")
if !c.IsPrivate() {
t.Error("The Channel must be private")
t.Errorf("c.IsPrivate() == %t, wants %t", c.IsPrivate(), true)
}
}
@@ -32,7 +32,7 @@ func TestIsPresence(t *testing.T) {
c := newChannel("presence-channel")
if !c.IsPresence() {
t.Error("The Channel must be presence")
t.Errorf("c.IsPresence() == %t, wants %t", c.IsPresence(), true)
}
}
@@ -40,7 +40,7 @@ func TestIsPublic(t *testing.T) {
c := newChannel("channel")
if !c.IsPublic() {
t.Error("The Channel must be public")
t.Errorf("c.IsPublic() == %t, wants %t", c.IsPublic(), true)
}
}
@@ -48,13 +48,13 @@ func TestIsPrivateOrPresence(t *testing.T) {
c := newChannel("private-channel")
if !c.IsPresenceOrPrivate() {
t.Error("The Channel must be private or presence")
t.Errorf("c.IsPresenceOrPrivate() == %t, wants %t", c.IsPresenceOrPrivate(), true)
}
c = newChannel("presence-channel")
if !c.IsPresenceOrPrivate() {
t.Error("The Channel must be private or presence")
t.Errorf("c.IsPresenceOrPrivate() == %t, wants %t", c.IsPresenceOrPrivate(), true)
}
}
@@ -62,7 +62,7 @@ func TestTotalSubscriptions(t *testing.T) {
c := newChannel("ID")
if c.TotalSubscriptions() != len(c.Subscriptions) {
t.Error("TotalSubscriptions must be equal to len of total subscriptions")
t.Errorf("c.TotalSubscriptions() == %d, wants %d", c.TotalSubscriptions(), len(c.Subscriptions))
}
}
@@ -73,11 +73,11 @@ func TestTotalUsers(t *testing.T) {
c.Subscriptions["2"] = newSubscription(newConnection("ID", nil), "")
if c.TotalSubscriptions() != len(c.Subscriptions) {
t.Error("TotalSubscriptions must be equal to len of total subscriptions")
t.Errorf("c.TotalSubscriptions() == %d, wants %d", c.TotalSubscriptions(), len(c.Subscriptions))
}
if c.TotalUsers() != 1 {
t.Error("TotalUsers must be equal to 1")
t.Errorf("c.TotalUsers() == %d, wants %d", c.TotalUsers(), 1)
}
}
@@ -87,12 +87,12 @@ func TestIsSubscribed(t *testing.T) {
conn := newConnection("ID", nil)
if c.IsSubscribed(conn) {
t.Error("Must not be subscribed")
t.Errorf("c.IsSubscribed(%q) == %t, wants %t", conn, c.IsSubscribed(conn), false)
}
c.Subscriptions["ID"] = newSubscription(conn, "")
if !c.IsSubscribed(conn) {
t.Error("Must be subscribed")
t.Errorf("c.IsSubscribed(%q) == %t, wants %t", conn, c.IsSubscribed(conn), true)
}
}
+3 -3
View File
@@ -17,14 +17,14 @@ func TestNewConnection(t *testing.T) {
c := newConnection(expectedSocketID, expectedSocket)
if c.SocketID != expectedSocketID {
t.Errorf("Expected: %s but got %s", expectedSocketID, c.SocketID)
t.Errorf("c.SocketID == %s, wants %s", c.SocketID, expectedSocketID)
}
if c.Socket != expectedSocket {
t.Errorf("Expected: %+v but got %+v", expectedSocket, c.Socket)
t.Errorf("c.Socket == %v, wants %v", c.Socket, expectedSocket)
}
if c.CreatedAt.IsZero() {
t.Errorf("Expected %s to not be zero", c.CreatedAt)
t.Errorf("c.CreatedAt.IsZero() == %t, wants %t", c.CreatedAt.IsZero(), false)
}
}