1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-23 22:45:11 +02:00
Files
starter/postgres_stek/postgres_stek_test.go

115 lines
2.7 KiB
Go
Raw Normal View History

2023-04-25 17:28:10 +03:00
package postgres_stek
import (
"errors"
2023-05-02 09:51:50 +03:00
"github.com/ManyakRus/starter/constants"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/tables/table_connections"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/connections"
2023-04-25 17:28:10 +03:00
"testing"
//log "github.com/sirupsen/logrus"
2023-12-26 16:42:53 +03:00
"github.com/ManyakRus/starter/config_main"
2023-05-02 09:51:50 +03:00
"github.com/ManyakRus/starter/contextmain"
"github.com/ManyakRus/starter/micro"
2023-04-25 17:28:10 +03:00
2023-05-02 09:51:50 +03:00
// logger "github.com/ManyakRus/starter/common/v0/logger"
"github.com/ManyakRus/starter/stopapp"
2023-04-25 17:28:10 +03:00
)
// CONNECTION - объект Соединение, настроенный
var CONNECTION = connections.Connection{Table_Connection: table_connections.Table_Connection{ID: constants.CONNECTION_ID, BranchID: constants.BRANCH_ID, IsLegal: true, Server: "10.1.9.153", Port: "5432", DbName: "kol_atom_ul_uni", DbScheme: "stack", Login: "", Password: ""}}
2023-04-25 17:28:10 +03:00
func TestConnect_err(t *testing.T) {
//Connect_Panic()
//ProgramDir := micro.ProgramDir_Common()
2023-12-26 16:42:53 +03:00
config_main.LoadEnv()
err := Connect_err(CONNECTION)
2023-04-25 17:28:10 +03:00
if err != nil {
t.Error("TestConnect error: ", err)
}
err = CloseConnection_err(CONNECTION)
2023-04-25 17:28:10 +03:00
if err != nil {
t.Error("TestConnect() error: ", err)
}
}
func TestIsClosed(t *testing.T) {
//ProgramDir := micro.ProgramDir_Common()
2023-12-26 16:42:53 +03:00
config_main.LoadEnv()
2023-04-25 17:28:10 +03:00
err := Connect_err(CONNECTION)
2023-04-25 17:28:10 +03:00
if err != nil {
t.Error("TestIsClosed Connect() error: ", err)
}
isClosed := IsClosed(CONNECTION)
2023-04-25 17:28:10 +03:00
if isClosed == true {
t.Error("TestIsClosed() isClosed = true ")
}
err = CloseConnection_err(CONNECTION)
2023-04-25 17:28:10 +03:00
if err != nil {
t.Error("TestIsClosed() CloseConnection() error: ", err)
}
}
func TestReconnect(t *testing.T) {
//ProgramDir := micro.ProgramDir_Common()
2023-12-26 16:42:53 +03:00
config_main.LoadEnv()
err := Connect_err(CONNECTION)
2023-04-25 17:28:10 +03:00
if err != nil {
t.Error("TestIsClosed Connect() error: ", err)
}
//ctx := context.Background()
Reconnect(CONNECTION, errors.New(""))
2023-04-25 17:28:10 +03:00
err = CloseConnection_err(CONNECTION)
2023-04-25 17:28:10 +03:00
if err != nil {
t.Error("TestReconnect() CloseConnection() error: ", err)
}
}
func TestWaitStop(t *testing.T) {
stopapp.StartWaitStop()
stopapp.GetWaitGroup_Main().Add(1)
go WaitStop()
micro.Pause(10)
//stopapp.SignalInterrupt <- syscall.SIGINT
contextmain.CancelContext()
}
func TestStartDB(t *testing.T) {
//ProgramDir := micro.ProgramDir_Common()
2023-12-26 16:42:53 +03:00
config_main.LoadEnv()
StartDB(CONNECTION)
err := CloseConnection_err(CONNECTION)
2023-04-25 17:28:10 +03:00
if err != nil {
t.Error("db_test.TestStartDB() CloseConnection() error: ", err)
}
}
func TestConnect(t *testing.T) {
//ProgramDir := micro.ProgramDir_Common()
2023-12-26 16:42:53 +03:00
config_main.LoadEnv()
Connect(CONNECTION)
2023-04-25 17:28:10 +03:00
CloseConnection(CONNECTION)
2023-04-25 17:28:10 +03:00
}
func TestGetConnection(t *testing.T) {
//ProgramDir := micro.ProgramDir_Common()
2023-12-26 16:42:53 +03:00
config_main.LoadEnv()
GetConnection(CONNECTION)
2023-04-25 17:28:10 +03:00
CloseConnection(CONNECTION)
2023-04-25 17:28:10 +03:00
}