Nuestro burocrata preferido: Sam Lowry https://lowry.sindominio.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
lowry/db/community_test.go

85 lines
1.9 KiB

package db
import (
"testing"
"time"
)
const (
communityName = "community"
communityHost = "host"
)
func TestAddCountCommunity(t *testing.T) {
db := initTestDB(t)
defer delTestDB(db)
count, err := db.CountCommunities(communityHost)
if err != nil {
t.Fatalf("Got an error counting communities: %v", err)
}
if count != 0 {
t.Errorf("Got an unexpected number of communities: %d", count)
}
err = db.AddCommunity(communityName, communityHost)
if err != nil {
t.Fatalf("Got an error adding a community: %v", err)
}
count, err = db.CountCommunities(communityHost)
if err != nil {
t.Fatalf("Got an error counting communities: %v", err)
}
if count != 1 {
t.Errorf("Got an unexpected number of communities: %d", count)
}
err = db.AddCommunity(communityName+"1", communityHost)
if err != nil {
t.Fatalf("Got an error adding a community: %v", err)
}
err = db.AddCommunity(communityName+"2", communityHost)
if err != nil {
t.Fatalf("Got an error adding a community: %v", err)
}
count, err = db.CountCommunities(communityHost)
if err != nil {
t.Fatalf("Got an error counting communities: %v", err)
}
if count != 3 {
t.Errorf("Got an unexpected number of communities: %d", count)
}
}
func TestExpireCommunities(t *testing.T) {
db := initTestDB(t)
defer delTestDB(db)
err := db.AddCommunity(communityName, communityHost)
if err != nil {
t.Fatalf("Got an error adding a community: %v", err)
}
count, err := db.CountCommunities(communityHost)
if err != nil {
t.Fatalf("Got an error counting communities: %v", err)
}
if count != 1 {
t.Errorf("Got an unexpected number of communities: %d", count)
}
err = db.ExpireCommunities(time.Microsecond)
if err != nil {
t.Fatalf("Got an error expiring invites: %v", err)
}
count, err = db.CountCommunities(communityHost)
if err != nil {
t.Fatalf("Got an error counting communities: %v", err)
}
if count != 0 {
t.Errorf("Got an unexpected number of communities: %d", count)
}
}