@@ -17,6 +17,7 @@ package main
1717import (
1818 "bytes"
1919 "context"
20+ "fmt"
2021 "os"
2122 "path/filepath"
2223 "testing"
@@ -326,3 +327,85 @@ func (suite *SubcommandTestSuite) TestAddExplicitPrereleaseWithoutPreFlag() {
326327version = '=0.9.0-alpha.1'
327328` , string (data ))
328329}
330+
331+ func (suite * SubcommandTestSuite ) TestAddPartialRegistryFailure () {
332+ // Initialize driver list
333+ m := InitCmd {Path : filepath .Join (suite .tempdir , "dbc.toml" )}.GetModel ()
334+ suite .runCmd (m )
335+
336+ // Test that add command handles partial registry failure gracefully
337+ // (one registry succeeds, another fails - returns both drivers and error)
338+ partialFailingRegistry := func () ([]dbc.Driver , error ) {
339+ // Get drivers from the test registry (simulating one successful registry)
340+ drivers , _ := getTestDriverRegistry ()
341+ // But also return an error (simulating another registry that failed)
342+ return drivers , fmt .Errorf ("registry https://cdn-fallback.example.com: failed to fetch driver registry: DNS resolution failed" )
343+ }
344+
345+ // Should succeed if the requested driver is found in the available drivers
346+ m = AddCmd {
347+ Path : filepath .Join (suite .tempdir , "dbc.toml" ),
348+ Driver : []string {"test-driver-1" },
349+ Pre : false ,
350+ }.GetModelCustom (
351+ baseModel {getDriverRegistry : partialFailingRegistry , downloadPkg : downloadTestPkg })
352+
353+ suite .runCmd (m )
354+ // Should succeed without printing the registry error
355+
356+ // Verify the file was updated correctly
357+ data , err := os .ReadFile (filepath .Join (suite .tempdir , "dbc.toml" ))
358+ suite .Require ().NoError (err )
359+ suite .Contains (string (data ), "[drivers.test-driver-1]" )
360+ }
361+
362+ func (suite * SubcommandTestSuite ) TestAddPartialRegistryFailureDriverNotFound () {
363+ // Initialize driver list
364+ m := InitCmd {Path : filepath .Join (suite .tempdir , "dbc.toml" )}.GetModel ()
365+ suite .runCmd (m )
366+
367+ // Test that add command shows registry errors when the requested driver is not found
368+ partialFailingRegistry := func () ([]dbc.Driver , error ) {
369+ // Get drivers from the test registry (simulating one successful registry)
370+ drivers , _ := getTestDriverRegistry ()
371+ // But also return an error (simulating another registry that failed)
372+ return drivers , fmt .Errorf ("registry https://cdn-fallback.example.com: failed to fetch driver registry: DNS resolution failed" )
373+ }
374+
375+ // Should fail with enhanced error message if the requested driver is not found
376+ m = AddCmd {
377+ Path : filepath .Join (suite .tempdir , "dbc.toml" ),
378+ Driver : []string {"nonexistent-driver" },
379+ Pre : false ,
380+ }.GetModelCustom (
381+ baseModel {getDriverRegistry : partialFailingRegistry , downloadPkg : downloadTestPkg })
382+
383+ out := suite .runCmdErr (m )
384+ // Should show the driver not found error AND the registry error
385+ suite .Contains (out , "driver `nonexistent-driver` not found" )
386+ suite .Contains (out , "Note: Some driver registries were unavailable" )
387+ suite .Contains (out , "failed to fetch driver registry" )
388+ suite .Contains (out , "DNS resolution failed" )
389+ }
390+
391+ func (suite * SubcommandTestSuite ) TestAddCompleteRegistryFailure () {
392+ // Initialize driver list
393+ m := InitCmd {Path : filepath .Join (suite .tempdir , "dbc.toml" )}.GetModel ()
394+ suite .runCmd (m )
395+
396+ // Test that add command handles complete registry failure (no drivers returned)
397+ completeFailingRegistry := func () ([]dbc.Driver , error ) {
398+ return nil , fmt .Errorf ("registry https://primary-cdn.example.com: network unreachable" )
399+ }
400+
401+ m = AddCmd {
402+ Path : filepath .Join (suite .tempdir , "dbc.toml" ),
403+ Driver : []string {"test-driver-1" },
404+ Pre : false ,
405+ }.GetModelCustom (
406+ baseModel {getDriverRegistry : completeFailingRegistry , downloadPkg : downloadTestPkg })
407+
408+ out := suite .runCmdErr (m )
409+ suite .Contains (out , "error getting driver list" )
410+ suite .Contains (out , "network unreachable" )
411+ }
0 commit comments