databricks-cli/internal
Pieter Noordhuis 4ccc70aeac
Consolidate environment variable interaction (#747)
## Changes

There are a couple places throughout the code base where interaction
with environment variables takes place. Moreover, more than one of these
would try to read a value from more than one environment variable as
fallback (for backwards compatibility). This change consolidates those
accesses.

The majority of diffs in this change are mechanical (i.e. add an
argument or replace a call).

This change:
* Moves common environment variable lookups for bundles to
`bundles/env`.
* Adds a `libs/env` package that wraps `os.LookupEnv` and `os.Getenv`
and allows for overrides to take place in a `context.Context`. By
scoping overrides to a `context.Context` we can avoid `t.Setenv` in
testing and unlock parallel test execution for integration tests.
* Updates call sites to pass through a `context.Context` where needed.
* For bundles, introduces `DATABRICKS_BUNDLE_ROOT` as new primary
variable instead of `BUNDLE_ROOT`. This was the last environment
variable that did not use the `DATABRICKS_` prefix.

## Tests

Unit tests pass.
2023-09-11 08:18:43 +00:00
..
acc Upgraded Go version to 1.21 (#664) 2023-08-15 13:50:40 +00:00
build Rename bricks -> databricks (#389) 2023-05-16 18:35:39 +02:00
bundle Use unique bundle root path for Python E2E test (#748) 2023-09-08 09:19:55 +00:00
testdata/import_dir Add workspace import-dir command (#456) 2023-06-12 21:03:46 +02:00
testutil Consolidate environment variable interaction (#747) 2023-09-11 08:18:43 +00:00
alerts_test.go Update alerts command integration test (#512) 2023-06-22 10:30:52 +02:00
api_test.go Rename bricks -> databricks (#389) 2023-05-16 18:35:39 +02:00
clusters_test.go Do not generate prompts for certain commands (#438) 2023-06-05 19:38:45 +02:00
filer_test.go Add filer.Filer implementation backed by the Files API (#474) 2023-06-19 18:29:13 +00:00
fs_cat_test.go Add TestAcc prefix to filer test and fix any failing tests (#611) 2023-07-26 13:03:10 +00:00
fs_cp_test.go Make local files default for fs commands (#506) 2023-06-23 16:07:09 +02:00
fs_ls_test.go Add TestAcc prefix to filer test and fix any failing tests (#611) 2023-07-26 13:03:10 +00:00
fs_mkdir_test.go Fix regex error check in mkdir integration test (#735) 2023-09-05 14:25:26 +00:00
fs_rm_test.go Add TestAcc prefix to filer test and fix any failing tests (#611) 2023-07-26 13:03:10 +00:00
git_clone_test.go Fix git clone integration test for non-existing repo (#610) 2023-07-27 13:51:57 +00:00
helpers.go Consolidate environment variable interaction (#747) 2023-09-11 08:18:43 +00:00
locker_test.go Correct name for force acquire deploy flag (#656) 2023-08-15 19:03:43 +00:00
repos_test.go Add provider detection to the repos create command (#528) 2023-06-27 14:17:13 +02:00
secrets_test.go Remove dependency on global state for remaining commands (#613) 2023-07-27 10:03:08 +00:00
sync_test.go Update Go SDK to v0.19.0 (#729) 2023-09-05 09:43:57 +00:00
version_test.go Use cmdio in version command for `--output` flag (#419) 2023-06-01 12:03:22 +02:00
workspace_test.go Decode contents by default in workspace export command (#531) 2023-06-27 20:42:29 +02:00