Run server test with PostgreSQL too
This commit is contained in:
parent
2b23828842
commit
2b8691ff40
@ -1,7 +1,9 @@
|
||||
package soju
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@ -15,7 +17,7 @@ const (
|
||||
testPassword = testUsername
|
||||
)
|
||||
|
||||
func createTempDB(t *testing.T) Database {
|
||||
func createTempSqliteDB(t *testing.T) Database {
|
||||
db, err := OpenDB("sqlite3", ":memory:")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temporary SQLite database: %v", err)
|
||||
@ -27,6 +29,15 @@ func createTempDB(t *testing.T) Database {
|
||||
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 {
|
||||
hashed, err := bcrypt.GenerateFromPassword([]byte(testPassword), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
@ -141,8 +152,7 @@ func registerUpstreamConn(t *testing.T, c ircConn) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestServer(t *testing.T) {
|
||||
db := createTempDB(t)
|
||||
func testServer(t *testing.T, db Database) {
|
||||
user := createTestUser(t, db)
|
||||
network, upstream := createTestUpstream(t, db, user)
|
||||
defer upstream.Close()
|
||||
@ -184,3 +194,15 @@ func TestServer(t *testing.T) {
|
||||
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