|
15 | 15 | package main |
16 | 16 |
|
17 | 17 | import ( |
| 18 | + "fmt" |
18 | 19 | "os" |
19 | 20 | "path/filepath" |
| 21 | + |
| 22 | + "github.com/columnar-tech/dbc" |
20 | 23 | ) |
21 | 24 |
|
22 | 25 | func (suite *SubcommandTestSuite) TestSync() { |
@@ -156,3 +159,87 @@ func (suite *SubcommandTestSuite) TestSyncInstallNoVerify() { |
156 | 159 | baseModel{getDriverRegistry: getTestDriverRegistry, downloadPkg: downloadTestPkg}) |
157 | 160 | suite.validateOutput("✓ test-driver-no-sig-1.1.0\r\n\rDone!\r\n", "", suite.runCmd(m)) |
158 | 161 | } |
| 162 | + |
| 163 | +func (suite *SubcommandTestSuite) TestSyncPartialRegistryFailure() { |
| 164 | + // Initialize driver list |
| 165 | + m := InitCmd{Path: filepath.Join(suite.tempdir, "dbc.toml")}.GetModel() |
| 166 | + suite.runCmd(m) |
| 167 | + |
| 168 | + m = AddCmd{Path: filepath.Join(suite.tempdir, "dbc.toml"), Driver: []string{"test-driver-1"}}.GetModel() |
| 169 | + suite.runCmd(m) |
| 170 | + |
| 171 | + // Test that sync command handles partial registry failure gracefully |
| 172 | + // (one registry succeeds, another fails - returns both drivers and error) |
| 173 | + partialFailingRegistry := func() ([]dbc.Driver, error) { |
| 174 | + // Get drivers from the test registry (simulating one successful registry) |
| 175 | + drivers, _ := getTestDriverRegistry() |
| 176 | + // But also return an error (simulating another registry that failed) |
| 177 | + return drivers, fmt.Errorf("registry https://backup-registry.example.com: failed to fetch driver registry: network timeout") |
| 178 | + } |
| 179 | + |
| 180 | + // Should succeed if the requested driver is found in the available drivers |
| 181 | + m = SyncCmd{ |
| 182 | + Path: filepath.Join(suite.tempdir, "dbc.toml"), |
| 183 | + }.GetModelCustom( |
| 184 | + baseModel{getDriverRegistry: partialFailingRegistry, downloadPkg: downloadTestPkg}) |
| 185 | + |
| 186 | + // Should install successfully without printing the registry error |
| 187 | + suite.validateOutput("✓ test-driver-1-1.1.0\r\n\rDone!\r\n", "", suite.runCmd(m)) |
| 188 | + suite.FileExists(filepath.Join(suite.tempdir, "test-driver-1.toml")) |
| 189 | +} |
| 190 | + |
| 191 | +func (suite *SubcommandTestSuite) TestSyncPartialRegistryFailureDriverNotFound() { |
| 192 | + // Initialize driver list with a driver that doesn't exist |
| 193 | + m := InitCmd{Path: filepath.Join(suite.tempdir, "dbc.toml")}.GetModel() |
| 194 | + suite.runCmd(m) |
| 195 | + |
| 196 | + // Manually create a driver list with a nonexistent driver |
| 197 | + err := os.WriteFile(filepath.Join(suite.tempdir, "dbc.toml"), []byte(`# dbc driver list |
| 198 | +[drivers] |
| 199 | +[drivers.nonexistent-driver] |
| 200 | +`), 0644) |
| 201 | + suite.Require().NoError(err) |
| 202 | + |
| 203 | + // Test that sync command shows registry errors when the requested driver is not found |
| 204 | + partialFailingRegistry := func() ([]dbc.Driver, error) { |
| 205 | + // Get drivers from the test registry (simulating one successful registry) |
| 206 | + drivers, _ := getTestDriverRegistry() |
| 207 | + // But also return an error (simulating another registry that failed) |
| 208 | + return drivers, fmt.Errorf("registry https://backup-registry.example.com: failed to fetch driver registry: network timeout") |
| 209 | + } |
| 210 | + |
| 211 | + // Should fail with enhanced error message if the requested driver is not found |
| 212 | + m = SyncCmd{ |
| 213 | + Path: filepath.Join(suite.tempdir, "dbc.toml"), |
| 214 | + }.GetModelCustom( |
| 215 | + baseModel{getDriverRegistry: partialFailingRegistry, downloadPkg: downloadTestPkg}) |
| 216 | + |
| 217 | + out := suite.runCmdErr(m) |
| 218 | + // Should show the driver not found error AND the registry error |
| 219 | + suite.Contains(out, "driver `nonexistent-driver` not found") |
| 220 | + suite.Contains(out, "Note: Some driver registries were unavailable") |
| 221 | + suite.Contains(out, "failed to fetch driver registry") |
| 222 | + suite.Contains(out, "network timeout") |
| 223 | +} |
| 224 | + |
| 225 | +func (suite *SubcommandTestSuite) TestSyncCompleteRegistryFailure() { |
| 226 | + // Initialize driver list |
| 227 | + m := InitCmd{Path: filepath.Join(suite.tempdir, "dbc.toml")}.GetModel() |
| 228 | + suite.runCmd(m) |
| 229 | + |
| 230 | + m = AddCmd{Path: filepath.Join(suite.tempdir, "dbc.toml"), Driver: []string{"test-driver-1"}}.GetModel() |
| 231 | + suite.runCmd(m) |
| 232 | + |
| 233 | + // Test that sync command handles complete registry failure (no drivers returned) |
| 234 | + completeFailingRegistry := func() ([]dbc.Driver, error) { |
| 235 | + return nil, fmt.Errorf("registry https://primary-registry.example.com: connection refused") |
| 236 | + } |
| 237 | + |
| 238 | + m = SyncCmd{ |
| 239 | + Path: filepath.Join(suite.tempdir, "dbc.toml"), |
| 240 | + }.GetModelCustom( |
| 241 | + baseModel{getDriverRegistry: completeFailingRegistry, downloadPkg: downloadTestPkg}) |
| 242 | + |
| 243 | + out := suite.runCmdErr(m) |
| 244 | + suite.Contains(out, "connection refused") |
| 245 | +} |
0 commit comments