@@ -4,7 +4,7 @@ import {Server} from 'node:net';
44
55import { ux } from '@oclif/core'
66import { utils } from '@heroku/heroku-cli-util'
7- import { parseExclusions , prepare , maybeTunnel } from '../../../../src/lib/pg/push_pull.js'
7+ import { parseExclusions , prepare , maybeTunnel , connArgs } from '../../../../src/lib/pg/push_pull.js'
88
99describe ( 'push_pull' , function ( ) {
1010 describe ( 'parseExclusions' , function ( ) {
@@ -140,4 +140,55 @@ describe('push_pull', function () {
140140 expect ( result . user ) . to . equal ( target . user )
141141 } )
142142 } )
143+
144+ describe ( 'connArgs' , function ( ) {
145+ it ( 'pushes the -U, -h, -p, and -d flags into the args array when connection details contain a user, host, and port and skipDFlag is not specified' , function ( ) {
146+ const actual = connArgs ( { user : 'john-rambo' , host : 'heroku.com' , port : 5432 } as any )
147+ const expected = [ '-U' , 'john-rambo' , '-h' , 'heroku.com' , '-p' , 5432 , '-d' , undefined ]
148+
149+ expect ( actual ) . to . eql ( expected )
150+ } )
151+
152+ it ( 'does not push a -U flag into the args array when connection details do not contain a user' , function ( ) {
153+ const actual = connArgs ( { host : 'heroku.com' , port : 5432 } as any )
154+ const expected = [ '-h' , 'heroku.com' , '-p' , 5432 , '-d' , undefined ]
155+
156+ expect ( actual ) . to . eql ( expected )
157+ } )
158+
159+ it ( 'does not push a -h flag into the args array when connection details do not contain a host' , function ( ) {
160+ const actual = connArgs ( { user : 'john-rambo' , port : 5432 } as any )
161+ const expected = [ '-U' , 'john-rambo' , '-p' , 5432 , '-d' , undefined ]
162+
163+ expect ( actual ) . to . eql ( expected )
164+ } )
165+
166+ it ( 'does not push a -p flag into the args array when connection details do not contain a port' , function ( ) {
167+ const actual = connArgs ( { user : 'john-rambo' , host : 'heroku.com' } as any )
168+ const expected = [ '-U' , 'john-rambo' , '-h' , 'heroku.com' , '-d' , undefined ]
169+
170+ expect ( actual ) . to . eql ( expected )
171+ } )
172+
173+ it ( 'pushes the -d flag into the args array when the `skipDFlag` argument is provided as `false`' , function ( ) {
174+ const actual = connArgs ( { user : 'john-rambo' , host : 'heroku.com' , port : 5432 } as any , false )
175+ const expected = [ '-U' , 'john-rambo' , '-h' , 'heroku.com' , '-p' , 5432 , '-d' , undefined ]
176+
177+ expect ( actual ) . to . eql ( expected )
178+ } )
179+
180+ it ( 'does not push a -d flag into the args array when the `skipDFlag` argument is provided as `true`' , function ( ) {
181+ const actual = connArgs ( { user : 'john-rambo' , host : 'heroku.com' , port : 5432 } as any , true )
182+ const expected = [ '-U' , 'john-rambo' , '-h' , 'heroku.com' , '-p' , 5432 , undefined ]
183+
184+ expect ( actual ) . to . eql ( expected )
185+ } )
186+
187+ it ( 'pushes the connection detail value for database into the args array' , function ( ) {
188+ const actual = connArgs ( { user : 'john-rambo' , host : 'heroku.com' , port : 5432 , database : 'favorite-candy' } as any )
189+ const expected = [ '-U' , 'john-rambo' , '-h' , 'heroku.com' , '-p' , 5432 , '-d' , 'favorite-candy' ]
190+
191+ expect ( actual ) . to . eql ( expected )
192+ } )
193+ } )
143194} )
0 commit comments