review test database and fix config restserver
parent
d379223517
commit
f5a652c13b
|
@ -1,3 +1,5 @@
|
|||
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"]
|
|
@ -1,2 +1,2 @@
|
|||
CREATE User test 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 USER test11 WITH PASSWORD 'test' CREATEDB;
|
||||
CREATE DATABASE test11 with owner = test11 ENCODING = 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8' TABLESPACE = pg_default CONNECTION LIMIT = -1;
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"log"
|
||||
|
||||
"git.ukamnya.ru/stulyaganov/RestApi/internal/restserver"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -18,6 +19,7 @@ func init() {
|
|||
func main() {
|
||||
|
||||
flag.Parse()
|
||||
godotenv.Load(".env")
|
||||
|
||||
config := restserver.NewConfig()
|
||||
if err := config.SetConfig(configPath); err != nil {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
version: '3.5'
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
database:
|
||||
|
|
1
go.mod
1
go.mod
|
@ -14,6 +14,7 @@ require (
|
|||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/jackc/pgx v3.6.2+incompatible // indirect
|
||||
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/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -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/v5 v5.2.0 h1:NdPpngX0Y6z6XDFKqmFQaE+bCtkqzvQIOt1wvBlAqs8=
|
||||
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/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
|
|
|
@ -12,7 +12,7 @@ var (
|
|||
func TestMain(m *testing.M) {
|
||||
database := os.Getenv("DATABASE_URL")
|
||||
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())
|
||||
|
|
|
@ -5,5 +5,7 @@ type ConfigBD struct {
|
|||
}
|
||||
|
||||
func NewConfig() *ConfigBD {
|
||||
return &ConfigBD{}
|
||||
return &ConfigBD{
|
||||
BaseUrlBd: "host=localhost user=admin password=root dbname=postgres sslmode=disable",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
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")
|
||||
u, err := s.Films().Create(&model.Films{
|
||||
Id: 11,
|
||||
|
|
|
@ -12,7 +12,7 @@ func Testdb(t *testing.T, databaseurl string) (*Bd, func(...string)) {
|
|||
config := NewConfig()
|
||||
config.BaseUrlBd = databaseurl
|
||||
s := New(config)
|
||||
|
||||
fmt.Println(config.BaseUrlBd)
|
||||
if err := s.Open(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue