fix: fix --short tests
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Dawid Wysokiński 2023-07-17 08:45:30 +02:00
parent 8f516e74e9
commit 037d557eef
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892
4 changed files with 17 additions and 13 deletions

View File

@ -1,6 +1,7 @@
package adapter_test
import (
"flag"
"fmt"
"log"
"net"
@ -14,19 +15,19 @@ import (
"github.com/pressly/goose/v3"
)
const (
envDBDSN = "TESTS_DB_DSN"
envRedisConnectionString = "TESTS_REDIS_CONNECTION_STRING"
var (
dbDSN = os.Getenv("TESTS_DB_DSN")
redisConnectionString = os.Getenv("TESTS_REDIS_CONNECTION_STRING")
)
func TestMain(m *testing.M) {
setUpGoose()
_, isDBDSNPresent := os.LookupEnv(envDBDSN)
_, isRedisConnectionStringPresent := os.LookupEnv(envRedisConnectionString)
// https://github.com/golang/go/blob/7cfa7d69259590319524c3715df4a39b39924bc3/src/testing/testing.go#L224
flag.Parse()
// all required envs are set, there is no need to use dockertest
if isDBDSNPresent && isRedisConnectionStringPresent {
if (dbDSN != "" && redisConnectionString != "") || testing.Short() {
os.Exit(m.Run())
}
@ -42,15 +43,15 @@ func TestMain(m *testing.M) {
var resources []*dockertest.Resource
if !isDBDSNPresent {
if dbDSN == "" {
resource, dsn := newPostgres(pool)
_ = os.Setenv(envDBDSN, dsn.String())
dbDSN = dsn.String()
resources = append(resources, resource)
}
if !isRedisConnectionStringPresent {
if redisConnectionString == "" {
resource, connString := newRedis(pool)
_ = os.Setenv(envRedisConnectionString, connString.String())
redisConnectionString = connString.String()
resources = append(resources, resource)
}

View File

@ -28,7 +28,7 @@ func newBunDB(tb testing.TB) *bun.DB {
schema := generateSchema()
sqldb := sql.OpenDB(
pgdriver.NewConnector(
pgdriver.WithDSN(os.Getenv(envDBDSN)),
pgdriver.WithDSN(dbDSN),
pgdriver.WithConnParams(map[string]any{
"search_path": schema,
}),

View File

@ -2,7 +2,6 @@ package adapter_test
import (
"context"
"os"
"testing"
"github.com/redis/go-redis/v9"
@ -12,7 +11,7 @@ import (
func newRedisClient(tb testing.TB) *redis.Client {
tb.Helper()
opts, err := redis.ParseURL(os.Getenv(envRedisConnectionString))
opts, err := redis.ParseURL(redisConnectionString)
require.NoError(tb, err, "couldn't parse redis connection string")
client := redis.NewClient(opts)

View File

@ -13,6 +13,10 @@ import (
func TestVillageRedis_SaveTranslateCoordsParams_GetTranslateCoordsParams(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping long-running test")
}
repo := adapter.NewVillageRedis(newRedisClient(t))
params, err := domain.NewTranslateVillageCoordsParams("pl", "pl181", "123|123 898|123", 20)