-
Notifications
You must be signed in to change notification settings - Fork 6
fix: fix incorrect credentials path, create common config logic #231
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
Open
amoeba
wants to merge
1
commit into
columnar-tech:main
Choose a base branch
from
amoeba:fix/dbc-config-locations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−33
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
| ) | ||
|
|
||
| // Get a platform-specific config dir for reading and writing dbc config files | ||
| // and credentails | ||
| func GetDbcConfigDir() (string, error) { | ||
| userdir, err := os.UserConfigDir() | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to get dbc configuration directory: %v", err) | ||
| } | ||
|
|
||
| orgDirName := "columnar" | ||
| if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { | ||
| orgDirName = "Columnar" | ||
| } | ||
| dbcDirName := "dbc" | ||
|
|
||
| return filepath.Join(userdir, orgDirName, dbcDirName), nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGetDbcConfigDirBasicTest(t *testing.T) { | ||
| dir, err := GetDbcConfigDir() | ||
| require.NoError(t, err) | ||
| assert.NotEmpty(t, dir) | ||
| assert.True(t, filepath.IsAbs(dir), "should return absolute path") | ||
| } | ||
|
|
||
| func TestGetDbcConfigDirCapitalization(t *testing.T) { | ||
| dir, err := GetDbcConfigDir() | ||
| require.NoError(t, err) | ||
| assert.NotEmpty(t, dir) | ||
|
|
||
| parent := filepath.Dir(dir) | ||
| orgName := filepath.Base(parent) | ||
|
|
||
| if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { | ||
| assert.Equal(t, "Columnar", orgName) | ||
| } else { | ||
| assert.Equal(t, "columnar", orgName) | ||
| } | ||
| } | ||
|
|
||
| func TestGetDbcConfigDirDarwin(t *testing.T) { | ||
| if runtime.GOOS != "darwin" { | ||
| t.Skip("skipping macOS-specific test") | ||
| } | ||
| dir, err := GetDbcConfigDir() | ||
| require.NoError(t, err) | ||
| home, _ := os.UserHomeDir() | ||
| assert.Equal(t, filepath.Join(home, "Library/Application Support/Columnar/dbc"), dir) | ||
| } | ||
|
|
||
| func TestGetDbcConfigDirLinux(t *testing.T) { | ||
| if runtime.GOOS != "linux" { | ||
| t.Skip("skipping Linux-specific test") | ||
| } | ||
| dir, err := GetDbcConfigDir() | ||
| require.NoError(t, err) | ||
| home, _ := os.UserHomeDir() | ||
| assert.Equal(t, filepath.Join(home, ".config/columnar/dbc"), dir) | ||
| } | ||
|
|
||
| func TestGetDbcConfigDirWindows(t *testing.T) { | ||
| if runtime.GOOS != "windows" { | ||
| t.Skip("skipping Windows-specific test") | ||
| } | ||
| dir, err := GetDbcConfigDir() | ||
| require.NoError(t, err) | ||
| appData := os.Getenv("AppData") | ||
| assert.Equal(t, filepath.Join(appData, "Columnar", "dbc"), dir) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but you were the one who said I should use
XDG_DATA_HOMEif it exists.... lolThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right. 🤦 This still fixes the original issue that was reported. Let me think about it and I'll tweak this so it uses XDG_DATA_DIR on Linuxes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which would make this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be
XDG_DATA_HOME, there is noXDG_DATA_DIRthere isXDG_DATA_DIRSwhich is a list of pathsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and we should still check
XDG_DATA_HOMEon macOS too. According to Apple's docs, the equivalent forXDG_DATA_HOMEon macOS is~/Library/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that last bit I didn't know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe my idea was bad, I'll think about it more when I'm back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, that's why it was using the logic I laid out. which was separate from the XDG_CONFIG_HOME (os.UserConfigDir) heh