Skip to content

Commit de9c4f0

Browse files
amoebazeroshade
andauthored
fix: add test for environment variable precedence (#60)
I saw while writing docs that we don't have an explicit test of the precedence chain we document so I created one. However, it current fails in a very strange way for me so this PR adds a failing test. --------- Co-authored-by: Matt Topol <[email protected]>
1 parent b7c784c commit de9c4f0

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

cmd/dbc/install_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,41 @@ func (suite *SubcommandTestSuite) TestInstallVenv() {
120120
"\nInstalled test-driver-1 1.1.0 to "+filepath.Join(suite.tempdir, "etc", "adbc", "drivers")+"\n", suite.runCmd(m))
121121
}
122122

123+
func (suite *SubcommandTestSuite) TestInstallEnvironmentPrecedence() {
124+
// Like the driver managers, dbc follows a precedence chain when
125+
// ADBC_DRIVER_MANAGER, VIRTUAL_ENV, and CONDA_PREFIX are set with each
126+
// variable overriding the next.
127+
driver_path := filepath.Join(suite.tempdir, "driver_path")
128+
venv_path := filepath.Join(suite.tempdir, "venv_path")
129+
conda_path := filepath.Join(suite.tempdir, "conda_path")
130+
os.Setenv("ADBC_DRIVER_PATH", driver_path)
131+
os.Setenv("VIRTUAL_ENV", venv_path)
132+
os.Setenv("CONDA_PREFIX", conda_path)
133+
134+
m := InstallCmd{Driver: "test-driver-1", Level: config.ConfigEnv}.
135+
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
136+
suite.runCmd(m)
137+
138+
suite.FileExists(filepath.Join(driver_path, "test-driver-1.toml"))
139+
suite.NoFileExists(filepath.Join(venv_path, "test-driver-1.toml"))
140+
suite.NoFileExists(filepath.Join(conda_path, "test-driver-1.toml"))
141+
142+
os.Unsetenv("ADBC_DRIVER_PATH")
143+
m = InstallCmd{Driver: "test-driver-1", Level: config.ConfigEnv}.
144+
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
145+
suite.runCmd(m)
146+
suite.FileExists(filepath.Join(venv_path, "etc", "adbc", "drivers", "test-driver-1.toml"))
147+
suite.NoFileExists(filepath.Join(conda_path, "etc", "adbc", "drivers", "test-driver-1.toml"))
148+
149+
os.Unsetenv("VIRTUAL_ENV")
150+
m = InstallCmd{Driver: "test-driver-1", Level: config.ConfigEnv}.
151+
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
152+
suite.runCmd(m)
153+
suite.FileExists(filepath.Join(conda_path, "etc", "adbc", "drivers", "test-driver-1.toml"))
154+
155+
os.Unsetenv("CONDA_PREFIX")
156+
}
157+
123158
func (suite *SubcommandTestSuite) TestInstallCondaPrefix() {
124159
os.Unsetenv("ADBC_DRIVER_PATH")
125160
os.Setenv("CONDA_PREFIX", suite.tempdir)

config/dirs_unixlike.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ func GetDriver(cfg Config, driverName string) (DriverInfo, error) {
8484
}
8585

8686
func CreateManifest(cfg Config, driver DriverInfo) (err error) {
87-
return createDriverManifest(cfg.Location, driver)
87+
loc, err := EnsureLocation(cfg)
88+
if err != nil {
89+
return err
90+
}
91+
return createDriverManifest(loc, driver)
8892
}
8993

9094
func UninstallDriver(cfg Config, info DriverInfo) error {

config/dirs_windows.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ func CreateManifest(cfg Config, driver DriverInfo) (err error) {
230230
if cfg.Location == "" {
231231
return fmt.Errorf("cannot write manifest to env config without %s set", adbcEnvVar)
232232
}
233-
return createDriverManifest(cfg.Location, driver)
233+
loc, err := EnsureLocation(cfg)
234+
if err != nil {
235+
return err
236+
}
237+
return createDriverManifest(loc, driver)
234238
}
235239

236240
var k registry.Key

0 commit comments

Comments
 (0)