@@ -168,6 +168,83 @@ func TestPoolerConfig(t *testing.T) {
168168 })
169169}
170170
171+ func TestSetConnectSuggestion (t * testing.T ) {
172+ oldProfile := CurrentProfile
173+ CurrentProfile = allProfiles [0 ]
174+ defer t .Cleanup (func () { CurrentProfile = oldProfile })
175+
176+ cases := []struct {
177+ name string
178+ err error
179+ suggestion string
180+ debug bool
181+ }{
182+ {
183+ name : "no-op on nil error" ,
184+ err : nil ,
185+ suggestion : "" ,
186+ },
187+ {
188+ name : "no-op on unrecognised error" ,
189+ err : errors .New ("some unknown error" ),
190+ suggestion : "" ,
191+ },
192+ {
193+ name : "connection refused" ,
194+ err : errors .New ("connect: connection refused" ),
195+ suggestion : "Make sure your local IP is allowed in Network Restrictions and Network Bans" ,
196+ },
197+ {
198+ name : "address not in allow list" ,
199+ err : errors .New ("server error (FATAL: Address not in tenant allow_list: {1,2,3} (SQLSTATE XX000))" ),
200+ suggestion : "Make sure your local IP is allowed in Network Restrictions and Network Bans" ,
201+ },
202+ {
203+ name : "ssl required without debug flag" ,
204+ err : errors .New ("SSL connection is required" ),
205+ suggestion : "" ,
206+ },
207+ {
208+ name : "ssl required with debug flag" ,
209+ err : errors .New ("SSL connection is required" ),
210+ debug : true ,
211+ suggestion : "SSL connection is not supported with --debug flag" ,
212+ },
213+ {
214+ name : "wrong password via SCRAM" ,
215+ err : errors .New ("SCRAM exchange: Wrong password" ),
216+ suggestion : "Connect to your database by setting the env var correctly: SUPABASE_DB_PASSWORD" ,
217+ },
218+ {
219+ name : "failed SASL auth" ,
220+ err : errors .New ("failed SASL auth" ),
221+ suggestion : "Connect to your database by setting the env var correctly: SUPABASE_DB_PASSWORD" ,
222+ },
223+ {
224+ name : "no route to host" ,
225+ err : errors .New ("connect: no route to host" ),
226+ suggestion : "Make sure your project exists on profile: " + CurrentProfile .Name ,
227+ },
228+ {
229+ name : "tenant or user not found" ,
230+ err : errors .New ("Tenant or user not found" ),
231+ suggestion : "Make sure your project exists on profile: " + CurrentProfile .Name ,
232+ },
233+ }
234+ for _ , tc := range cases {
235+ t .Run (tc .name , func (t * testing.T ) {
236+ CmdSuggestion = ""
237+ viper .Set ("DEBUG" , tc .debug )
238+ SetConnectSuggestion (tc .err )
239+ if tc .suggestion == "" {
240+ assert .Empty (t , CmdSuggestion )
241+ } else {
242+ assert .Contains (t , CmdSuggestion , tc .suggestion )
243+ }
244+ })
245+ }
246+ }
247+
171248func TestPostgresURL (t * testing.T ) {
172249 url := ToPostgresURL (pgconn.Config {
173250 Host : "2406:da18:4fd:9b0d:80ec:9812:3e65:450b" ,
0 commit comments