77 "testing"
88 "time"
99
10- pgx "github.com/jackc/pgx/v5"
11- "github.com/jackc/pgx/v5/pgtype"
10+ pgtype "github.com/jackc/pgx/v5/pgtype"
1211 "github.com/stretchr/testify/assert"
1312 "github.com/stretchr/testify/require"
1413
@@ -51,11 +50,11 @@ func SetupTestCase(t *testing.T) func(t *testing.T) {
5150}
5251
5352// setupTestRenoteDBFunc used to connect to remote postgreSQL database
54- var setupTestRemoteDBFunc = func () (pgengine.PgxConnIface , pgx. Tx , error ) {
53+ var setupTestRemoteDBFunc = func () (pgengine.PgxConnIface , error ) {
5554 c := cmdOpts .Connection
5655 connstr := fmt .Sprintf ("host='%s' port='%d' sslmode='%s' dbname='%s' user='%s' password='%s'" ,
5756 c .Host , c .Port , c .SSLMode , c .DBName , c .User , c .Password )
58- return pge .GetRemoteDBTransaction (context .Background (), connstr )
57+ return pge .GetRemoteDBConnection (context .Background (), connstr )
5958}
6059
6160func TestInitAndTestConfigDBConnection (t * testing.T ) {
@@ -134,23 +133,23 @@ func TestSchedulerFunctions(t *testing.T) {
134133
135134 ctx := context .Background ()
136135
137- t .Run ("Check DeleteChainConfig funсtion " , func (t * testing.T ) {
136+ t .Run ("Check DeleteChainConfig function " , func (t * testing.T ) {
138137 assert .Equal (t , false , pge .DeleteChain (ctx , 0 ), "Should not delete in clean database" )
139138 })
140139
141- t .Run ("Check GetChainElements funсtion " , func (t * testing.T ) {
140+ t .Run ("Check GetChainElements function " , func (t * testing.T ) {
142141 var chains []pgengine.ChainTask
143- tx , txid , err := pge .StartTransaction (ctx , 0 )
142+ tx , txid , err := pge .StartTransaction (ctx )
144143 assert .NoError (t , err , "Should start transaction" )
145144 assert .Greater (t , txid , int64 (0 ), "Should return transaction id" )
146145 assert .NoError (t , pge .GetChainElements (ctx , & chains , 0 ), "Should no error in clean database" )
147146 assert .Empty (t , chains , "Should be empty in clean database" )
148147 pge .CommitTransaction (ctx , tx )
149148 })
150149
151- t .Run ("Check GetChainParamValues funсtion " , func (t * testing.T ) {
150+ t .Run ("Check GetChainParamValues function " , func (t * testing.T ) {
152151 var paramVals []string
153- tx , txid , err := pge .StartTransaction (ctx , 0 )
152+ tx , txid , err := pge .StartTransaction (ctx )
154153 assert .NoError (t , err , "Should start transaction" )
155154 assert .Greater (t , txid , int64 (0 ), "Should return transaction id" )
156155 assert .NoError (t , pge .GetChainParamValues (ctx , & paramVals , & pgengine.ChainTask {
@@ -160,15 +159,15 @@ func TestSchedulerFunctions(t *testing.T) {
160159 pge .CommitTransaction (ctx , tx )
161160 })
162161
163- t .Run ("Check InsertChainRunStatus funсtion " , func (t * testing.T ) {
162+ t .Run ("Check InsertChainRunStatus function " , func (t * testing.T ) {
164163 var res bool
165164 assert .NotPanics (t , func () { res = pge .InsertChainRunStatus (ctx , 0 , 1 ) },
166165 "Should no error in clean database" )
167166 assert .True (t , res , "Active chain should be inserted" )
168167 })
169168
170169 t .Run ("Check ExecuteSQLCommand function" , func (t * testing.T ) {
171- tx , txid , err := pge .StartTransaction (ctx , 0 )
170+ tx , txid , err := pge .StartTransaction (ctx )
172171 assert .NoError (t , err , "Should start transaction" )
173172 assert .Greater (t , txid , int64 (0 ), "Should return transaction id" )
174173 f := func (sql string , params []string ) error {
@@ -191,30 +190,17 @@ func TestSchedulerFunctions(t *testing.T) {
191190func TestGetRemoteDBTransaction (t * testing.T ) {
192191 teardownTestCase := SetupTestCase (t )
193192 defer teardownTestCase (t )
194-
195193 ctx := context .Background ()
196-
197- remoteDb , tx , err := setupTestRemoteDBFunc ()
198- defer pge .FinalizeRemoteDBConnection (ctx , remoteDb )
194+ remoteDb , err := setupTestRemoteDBFunc ()
195+ defer pge .FinalizeDBConnection (ctx , remoteDb )
199196 require .NoError (t , err , "remoteDB should be initialized" )
200197 require .NotNil (t , remoteDb , "remoteDB should be initialized" )
201198
202- t .Run ("Check connection closing" , func (t * testing.T ) {
203- pge .FinalizeRemoteDBConnection (ctx , remoteDb )
204- assert .NotNil (t , remoteDb , "Connection isn't closed properly" )
205- })
206-
207- t .Run ("Check set role function" , func (t * testing.T ) {
208- var runUID pgtype.Text
209- runUID .String = cmdOpts .Connection .User
210- assert .NotPanics (t , func () { pge .SetRole (ctx , tx , runUID ) }, "Set Role failed" )
211- })
212-
213- t .Run ("Check reset role function" , func (t * testing.T ) {
214- assert .NotPanics (t , func () { pge .ResetRole (ctx , tx ) }, "Reset Role failed" )
215- })
216-
217- pge .CommitTransaction (ctx , tx )
199+ assert .NoError (t , pge .SetRole (ctx , remoteDb , pgtype.Text {String : cmdOpts .Connection .User , Valid : true }),
200+ "Set Role failed" )
201+ assert .NotPanics (t , func () { pge .ResetRole (ctx , remoteDb ) }, "Reset Role failed" )
202+ pge .FinalizeDBConnection (ctx , remoteDb )
203+ assert .NotNil (t , remoteDb , "Connection isn't closed properly" )
218204}
219205
220206func TestSamplesScripts (t * testing.T ) {
0 commit comments