-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cli/config/configfile: Atomically rewrite the config file when saving. #1359
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ package configfile | |
|
|
||
| import ( | ||
| "fmt" | ||
| "io/ioutil" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/docker/cli/cli/config/credentials" | ||
|
|
@@ -413,3 +415,13 @@ func TestCheckKubernetesConfigurationRaiseAnErrorOnInvalidValue(t *testing.T) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| func TestSave(t *testing.T) { | ||
| configFile := New("test-save") | ||
| defer os.Remove("test-save") | ||
| err := configFile.Save() | ||
| assert.NilError(t, err) | ||
| cfg, err := ioutil.ReadFile("test-save") | ||
| assert.NilError(t, err) | ||
| assert.Check(t, is.Equal(string(cfg), "{\n \"auths\": {}\n}")) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels like an omitempty tag is missing in the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can fix in another PR
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Review after merge (so maybe for the just opened follow-up) 😅: assert.Check(t, is.Equal(string(cfg), `{
"auths": {}
}`)) |
||
| } | ||
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.
nit; if the rename fails we'll leave behind the temp file.
Chances are probably slim that that happens, so I'm ok with keeping this as-is (we can do a follow-up if we think that's a concern)
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.
I feel it's not that big of a deal, so I'm ok keeping as-is and do a follow-up if we need 👼
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.
alrighty; let's get this merged; thanks!
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.
Excellent catch! Fixed in #1366 since this one already sailed.