Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added env.UserHomeDir(ctx) for parallel-friendly tests #955

Merged
merged 5 commits into from
Nov 8, 2023
Merged

Conversation

nfx
Copy link
Contributor

@nfx nfx commented Nov 6, 2023

Changes

os.Getenv(..) is not friendly with libs/env. This PR makes the relevant changes to places where we need to read user home directory.

Tests

Mainly done in #914

`os.Getenv(..)` is not friendly with `libs/env`. This PR makes the relevant changes to places where we need to read user home directory.
@nfx nfx requested a review from pietern November 6, 2023 20:28
@nfx nfx enabled auto-merge November 7, 2023 09:11
@nfx nfx added the Tech Debt Issues related to technical debt (tests, refactoring and etc.) label Nov 7, 2023
cmd/root/auth.go Outdated Show resolved Hide resolved
cmd/root/auth.go Outdated Show resolved Hide resolved
libs/databrickscfg/profiles_test.go Outdated Show resolved Hide resolved
}

func UserHomeDir(ctx context.Context) string {
return Get(ctx, homeEnvVar())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So os.UserHomeDir returns an error if it is empty. This silently returns an empty string. We should return an error here as well to avoid doing the wrong thing when the home directory inadvertently is not set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which can be the cases when HOME is empty?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users may exec into an environment where it is not set, i.e. a container, or empty env.

The important bit is that we should never silently do the wrong thing, so we should either return an error from this function (reasonable), or panic if the value is empty (not great).

libs/env/loader.go Show resolved Hide resolved
@nfx nfx requested a review from pietern November 7, 2023 23:57
Copy link
Contributor

@pietern pietern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests fail because not all code paths end up cleaning the path. To fix the tests, you can call filepath.Clean from GetPath and from env.UserHomeDir (or where the string prefix check is made).

Everything else LGTM.

The panic on missing $HOME is risky, but we can go with it until we get evidence that it doesn't hold up everywhere. I spot checked a couple bare bones Docker containers and observe a $HOME everywhere.

libs/databrickscfg/profiles_test.go Outdated Show resolved Hide resolved
@nfx nfx added this pull request to the merge queue Nov 8, 2023
Merged via the queue into main with commit e68a88e Nov 8, 2023
4 checks passed
@nfx nfx deleted the env/user-home branch November 8, 2023 14:57
andrewnester added a commit that referenced this pull request Nov 8, 2023
CLI:
 * Hide `--progress-format` global flag ([#965](#965)).
 * Make configure command visible + fix bundle command description ([#961](#961)).
 * Log process ID in each log entry ([#949](#949)).
 * Improve error message when `--json` flag is specified ([#933](#933)).

Bundles:
 * Remove validation for default value against pattern ([#959](#959)).
 * Bundle path rewrites for dbt and SQL file tasks ([#962](#962)).
 * Initialize variable definitions that are defined without properties ([#966](#966)).

Internal:
 * Remove mention of Lakehouse apps from the changelog ([#945](#945)).
 * Function to merge two instances of `config.Value` ([#938](#938)).
 * Make to/from string methods private to the jsonschema package ([#942](#942)).
 * Make Cobra runner compatible with testing interactive flows ([#957](#957)).
 * Added `env.UserHomeDir(ctx)` for parallel-friendly tests ([#955](#955)).

Dependency updates:
 * Bump golang.org/x/mod from 0.13.0 to 0.14.0 ([#954](#954)).
 * Bump golang.org/x/text from 0.13.0 to 0.14.0 ([#953](#953)).
 * Bump golang.org/x/sync from 0.4.0 to 0.5.0 ([#951](#951)).
 * Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 ([#950](#950)).
 * Bump github.com/fatih/color from 1.15.0 to 1.16.0 ([#952](#952)).
@andrewnester andrewnester mentioned this pull request Nov 8, 2023
github-merge-queue bot pushed a commit that referenced this pull request Nov 8, 2023
CLI:
* Hide `--progress-format` global flag
([#965](#965)).
* Make configure command visible + fix bundle command description
([#961](#961)).
* Log process ID in each log entry
([#949](#949)).
* Improve error message when `--json` flag is specified
([#933](#933)).

Bundles:
* Remove validation for default value against pattern
([#959](#959)).
* Bundle path rewrites for dbt and SQL file tasks
([#962](#962)).
* Initialize variable definitions that are defined without properties
([#966](#966)).

Internal:
* Function to merge two instances of `config.Value`
([#938](#938)).
* Make to/from string methods private to the jsonschema package
([#942](#942)).
* Make Cobra runner compatible with testing interactive flows
([#957](#957)).
* Added `env.UserHomeDir(ctx)` for parallel-friendly tests
([#955](#955)).


Dependency updates:
* Bump golang.org/x/mod from 0.13.0 to 0.14.0
([#954](#954)).
* Bump golang.org/x/text from 0.13.0 to 0.14.0
([#953](#953)).
* Bump golang.org/x/sync from 0.4.0 to 0.5.0
([#951](#951)).
* Bump github.com/spf13/cobra from 1.7.0 to 1.8.0
([#950](#950)).
* Bump github.com/fatih/color from 1.15.0 to 1.16.0
([#952](#952)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tech Debt Issues related to technical debt (tests, refactoring and etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants