mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-15 10:53:09 -06:00
Use travis' postgres for testing
Signed-off-by: Maximilian Seifert <max.seifert@drglitch.net>
This commit is contained in:
parent
8b8b55d0a6
commit
7edf1a038a
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -13,6 +14,7 @@ import (
|
|||
var dataSource string
|
||||
var insideCi = false
|
||||
var insideDocker = false
|
||||
const dbName = "dendrite_device"
|
||||
|
||||
func init() {
|
||||
for _, val := range os.Environ() {
|
||||
|
|
@ -28,14 +30,30 @@ func init() {
|
|||
}
|
||||
|
||||
if insideCi {
|
||||
dataSource = "postgres://postgres@localhost/dendrite_device?sslmode=disable"
|
||||
dataSource = fmt.Sprintf("postgres://postgres@localhost/%s?sslmode=disable", dbName)
|
||||
} else if insideDocker {
|
||||
dataSource = "postgres://dendrite:itsasecret@postgres/dendrite_device?sslmode=disable"
|
||||
dataSource = fmt.Sprintf("postgres://dendrite:itsasecret@localhost/%s?sslmode=disable", dbName)
|
||||
} else {
|
||||
dataSource = "postgres://dendrite:itsasecret@localhost:15432/dendrite_device?sslmode=disable"
|
||||
dataSource = fmt.Sprintf("postgres://dendrite:itsasecret@localhost:15432/%s?sslmode=disable", dbName)
|
||||
}
|
||||
|
||||
|
||||
if insideCi {
|
||||
database := "dendrite_device"
|
||||
cmd := exec.Command("psql", database)
|
||||
cmd.Stdin = strings.NewReader(
|
||||
fmt.Sprintf("DROP DATABASE IF EXISTS %s; CREATE DATABASE %s;", database, database),
|
||||
)
|
||||
// Send stdout and stderr to our stderr so that we see error messages from
|
||||
// the psql process
|
||||
cmd.Stdout = os.Stderr
|
||||
cmd.Stderr = os.Stderr
|
||||
_ = cmd.Run()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
type deviceSpec struct {
|
||||
localPart string
|
||||
devID string
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@ package storage
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -14,6 +16,7 @@ import (
|
|||
var dataSource string
|
||||
var insideCi = false
|
||||
var insideDocker = false
|
||||
const dbName = "dendrite_syncapi"
|
||||
|
||||
func init() {
|
||||
for _, val := range os.Environ() {
|
||||
|
|
@ -29,11 +32,24 @@ func init() {
|
|||
}
|
||||
|
||||
if insideCi {
|
||||
dataSource = "postgres://postgres@localhost/dendrite_syncapi?sslmode=disable"
|
||||
dataSource = fmt.Sprintf("postgres://postgres@localhost/%s?sslmode=disable", dbName)
|
||||
} else if insideDocker {
|
||||
dataSource = "postgres://dendrite:itsasecret@postgres/dendrite_syncapi?sslmode=disable"
|
||||
dataSource = fmt.Sprintf("postgres://dendrite:itsasecret@localhost/%s?sslmode=disable", dbName)
|
||||
} else {
|
||||
dataSource = "postgres://dendrite:itsasecret@localhost:15432/dendrite_syncapi?sslmode=disable"
|
||||
dataSource = fmt.Sprintf("postgres://dendrite:itsasecret@localhost:15432/%s?sslmode=disable", dbName)
|
||||
}
|
||||
|
||||
if insideCi {
|
||||
database := "dendrite_syncapi"
|
||||
cmd := exec.Command("psql", database)
|
||||
cmd.Stdin = strings.NewReader(
|
||||
fmt.Sprintf("DROP DATABASE IF EXISTS %s; CREATE DATABASE %s;", database, database),
|
||||
)
|
||||
// Send stdout and stderr to our stderr so that we see error messages from
|
||||
// the psql process
|
||||
cmd.Stdout = os.Stderr
|
||||
cmd.Stderr = os.Stderr
|
||||
_ = cmd.Run()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue