review test database and fix config restserver

main
Shuhrat Tultaganov 2023-01-03 19:27:10 +03:00
parent d379223517
commit f5a652c13b
10 changed files with 17 additions and 8 deletions

View File

@ -1,3 +1,5 @@
FROM postgres FROM postgres
ADD ./docker-compose_test_db_init.sql /docker-entrypoint-initdb.d/ ADD docker-compose_test_db_init.sql /docker-entrypoint-initdb.d/docker-compose_test_db_init.sql
RUN chown -R postgres /docker-entrypoint-initdb.d/docker-compose_test_db_init.sql
# ENTRYPOINT ["docker-entrypoint.sh"]

View File

@ -1,2 +1,2 @@
CREATE User test with password 'test' createdb; CREATE USER test11 WITH PASSWORD 'test' CREATEDB;
CREATE DATABASE test with owner = test ENCODING = 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8' TABLESPACE = pg_default CONNECTION LIMIT = -1; CREATE DATABASE test11 with owner = test11 ENCODING = 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8' TABLESPACE = pg_default CONNECTION LIMIT = -1;

View File

@ -5,6 +5,7 @@ import (
"log" "log"
"git.ukamnya.ru/stulyaganov/RestApi/internal/restserver" "git.ukamnya.ru/stulyaganov/RestApi/internal/restserver"
"github.com/joho/godotenv"
) )
var ( var (
@ -18,6 +19,7 @@ func init() {
func main() { func main() {
flag.Parse() flag.Parse()
godotenv.Load(".env")
config := restserver.NewConfig() config := restserver.NewConfig()
if err := config.SetConfig(configPath); err != nil { if err := config.SetConfig(configPath); err != nil {

View File

@ -1,4 +1,4 @@
version: '3.5' version: '3.7'
services: services:
database: database:

1
go.mod
View File

@ -14,6 +14,7 @@ require (
github.com/gorilla/mux v1.8.0 // indirect github.com/gorilla/mux v1.8.0 // indirect
github.com/jackc/pgx v3.6.2+incompatible // indirect github.com/jackc/pgx v3.6.2+incompatible // indirect
github.com/jackc/pgx/v5 v5.2.0 github.com/jackc/pgx/v5 v5.2.0
github.com/joho/godotenv v1.4.0
github.com/lib/pq v1.10.7 // indirect github.com/lib/pq v1.10.7 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect

2
go.sum
View File

@ -11,6 +11,8 @@ github.com/jackc/pgx v3.6.2+incompatible h1:2zP5OD7kiyR3xzRYMhOcXVvkDZsImVXfj+yI
github.com/jackc/pgx v3.6.2+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= github.com/jackc/pgx v3.6.2+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
github.com/jackc/pgx/v5 v5.2.0 h1:NdPpngX0Y6z6XDFKqmFQaE+bCtkqzvQIOt1wvBlAqs8= github.com/jackc/pgx/v5 v5.2.0 h1:NdPpngX0Y6z6XDFKqmFQaE+bCtkqzvQIOt1wvBlAqs8=
github.com/jackc/pgx/v5 v5.2.0/go.mod h1:Ptn7zmohNsWEsdxRawMzk3gaKma2obW+NWTnKa0S4nk= github.com/jackc/pgx/v5 v5.2.0/go.mod h1:Ptn7zmohNsWEsdxRawMzk3gaKma2obW+NWTnKa0S4nk=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

View File

@ -12,7 +12,7 @@ var (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
database := os.Getenv("DATABASE_URL") database := os.Getenv("DATABASE_URL")
if database == "" { if database == "" {
database = "host=localhost user=admin password=root dbname=postgres sslmode=disable" database = "host=localhost user=test password=test dbname=test sslmode=disable"
} }
os.Exit(m.Run()) os.Exit(m.Run())

View File

@ -5,5 +5,7 @@ type ConfigBD struct {
} }
func NewConfig() *ConfigBD { func NewConfig() *ConfigBD {
return &ConfigBD{} return &ConfigBD{
BaseUrlBd: "host=localhost user=admin password=root dbname=postgres sslmode=disable",
}
} }

View File

@ -10,7 +10,7 @@ import (
func TestFilmRepo_Create(t *testing.T) { func TestFilmRepo_Create(t *testing.T) {
s, teardown := bd.Testdb(t, "host=localhost user=admin password=root dbname=postgres sslmode=disable") s, teardown := bd.Testdb(t, "host=localhost user=test password=test dbname=test sslmode=disable")
defer teardown("films") defer teardown("films")
u, err := s.Films().Create(&model.Films{ u, err := s.Films().Create(&model.Films{
Id: 11, Id: 11,

View File

@ -12,7 +12,7 @@ func Testdb(t *testing.T, databaseurl string) (*Bd, func(...string)) {
config := NewConfig() config := NewConfig()
config.BaseUrlBd = databaseurl config.BaseUrlBd = databaseurl
s := New(config) s := New(config)
fmt.Println(config.BaseUrlBd)
if err := s.Open(); err != nil { if err := s.Open(); err != nil {
t.Fatal(err) t.Fatal(err)
} }