Run server test with PostgreSQL too
This commit is contained in:
parent
2b23828842
commit
2b8691ff40
@ -1,7 +1,9 @@
|
|||||||
package soju
|
package soju
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
@ -15,7 +17,7 @@ const (
|
|||||||
testPassword = testUsername
|
testPassword = testUsername
|
||||||
)
|
)
|
||||||
|
|
||||||
func createTempDB(t *testing.T) Database {
|
func createTempSqliteDB(t *testing.T) Database {
|
||||||
db, err := OpenDB("sqlite3", ":memory:")
|
db, err := OpenDB("sqlite3", ":memory:")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create temporary SQLite database: %v", err)
|
t.Fatalf("failed to create temporary SQLite database: %v", err)
|
||||||
@ -27,6 +29,15 @@ func createTempDB(t *testing.T) Database {
|
|||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createTempPostgresDB(t *testing.T) Database {
|
||||||
|
db := &PostgresDB{db: openTempPostgresDB(t)}
|
||||||
|
if err := db.upgrade(); err != nil {
|
||||||
|
t.Fatalf("failed to upgrade PostgreSQL database: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
func createTestUser(t *testing.T, db Database) *User {
|
func createTestUser(t *testing.T, db Database) *User {
|
||||||
hashed, err := bcrypt.GenerateFromPassword([]byte(testPassword), bcrypt.DefaultCost)
|
hashed, err := bcrypt.GenerateFromPassword([]byte(testPassword), bcrypt.DefaultCost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -141,8 +152,7 @@ func registerUpstreamConn(t *testing.T, c ircConn) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer(t *testing.T) {
|
func testServer(t *testing.T, db Database) {
|
||||||
db := createTempDB(t)
|
|
||||||
user := createTestUser(t, db)
|
user := createTestUser(t, db)
|
||||||
network, upstream := createTestUpstream(t, db, user)
|
network, upstream := createTestUpstream(t, db, user)
|
||||||
defer upstream.Close()
|
defer upstream.Close()
|
||||||
@ -184,3 +194,15 @@ func TestServer(t *testing.T) {
|
|||||||
t.Fatalf("invalid NOTICE text: want %q, got: %v", noticeText, msg)
|
t.Fatalf("invalid NOTICE text: want %q, got: %v", noticeText, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServer(t *testing.T) {
|
||||||
|
t.Run("sqlite", func(t *testing.T) {
|
||||||
|
db := createTempSqliteDB(t)
|
||||||
|
testServer(t, db)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("postgres", func(t *testing.T) {
|
||||||
|
db := createTempPostgresDB(t)
|
||||||
|
testServer(t, db)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user