-
Notifications
You must be signed in to change notification settings - Fork 5
Simplify update notification flow #159
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c994215
Simplify update notification flow
gtsiolis fd95297
Remove option from update prompt
gtsiolis be9c4ee
Address review comments
gtsiolis 3e6e481
Persist skipped version to config
gtsiolis 644284f
Address review comments
gtsiolis 83095b2
clean-up
carole-lavillonniere 2bcd188
more tests
carole-lavillonniere ac13c0f
fix panic
carole-lavillonniere 1c49ef6
preserve config when setting toml value
carole-lavillonniere 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
Some comments aren't visible on the classic Files Changed page.
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
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,123 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/pelletier/go-toml/v2" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSetInFileAppendsWhenKeyAbsent(t *testing.T) { | ||
| path := filepath.Join(t.TempDir(), "config.toml") | ||
| original := `# User comment | ||
| [[containers]] | ||
| type = "aws" | ||
| port = "4566" | ||
| ` | ||
| require.NoError(t, os.WriteFile(path, []byte(original), 0644)) | ||
|
|
||
| require.NoError(t, setInFile(path, "cli.update_skipped_version", "v1.2.3")) | ||
|
|
||
| got, err := os.ReadFile(path) | ||
| require.NoError(t, err) | ||
| result := string(got) | ||
|
|
||
| assert.Contains(t, result, "# User comment") | ||
| assert.Contains(t, result, `type = "aws"`) | ||
| assert.Contains(t, result, "[cli]") | ||
| assert.Contains(t, result, `update_skipped_version = 'v1.2.3'`) | ||
|
|
||
| var parsed map[string]any | ||
| require.NoError(t, toml.Unmarshal(got, &parsed)) | ||
| } | ||
|
|
||
| func TestSetInFileReplacesExistingKeyInPlace(t *testing.T) { | ||
| path := filepath.Join(t.TempDir(), "config.toml") | ||
| original := `# Keep this | ||
| [[containers]] | ||
| type = "aws" | ||
|
|
||
| [cli] | ||
| update_skipped_version = "v1.0.0" | ||
| ` | ||
| require.NoError(t, os.WriteFile(path, []byte(original), 0644)) | ||
|
|
||
| require.NoError(t, setInFile(path, "cli.update_skipped_version", "v2.0.0")) | ||
|
|
||
| got, err := os.ReadFile(path) | ||
| require.NoError(t, err) | ||
| result := string(got) | ||
|
|
||
| assert.Contains(t, result, "# Keep this") | ||
| assert.Contains(t, result, `update_skipped_version = 'v2.0.0'`) | ||
| assert.NotContains(t, result, "v1.0.0") | ||
|
|
||
| var parsed map[string]any | ||
| require.NoError(t, toml.Unmarshal(got, &parsed)) | ||
| } | ||
|
|
||
| func TestSetInFilePreservesCommentsAndFormatting(t *testing.T) { | ||
| path := filepath.Join(t.TempDir(), "config.toml") | ||
| original := `# lstk configuration file | ||
| # Run 'lstk config path' to see where this file lives. | ||
|
|
||
| [[containers]] | ||
| type = "aws" # Emulator type | ||
| tag = "latest" # Docker image tag | ||
| port = "4566" # Host port | ||
|
|
||
| # Example profiles: | ||
| # [env.debug] | ||
| # DEBUG = "1" | ||
| ` | ||
| require.NoError(t, os.WriteFile(path, []byte(original), 0644)) | ||
|
|
||
| require.NoError(t, setInFile(path, "cli.update_skipped_version", "v1.2.3")) | ||
|
|
||
| got, err := os.ReadFile(path) | ||
| require.NoError(t, err) | ||
| result := string(got) | ||
|
|
||
| for _, want := range []string{ | ||
| "# lstk configuration file", | ||
| "# Run 'lstk config path' to see where this file lives.", | ||
| "# Emulator type", | ||
| "# Docker image tag", | ||
| "# Host port", | ||
| "# Example profiles:", | ||
| `# DEBUG = "1"`, | ||
| } { | ||
| assert.Contains(t, result, want, "expected comment preserved: %q", want) | ||
| } | ||
| } | ||
|
|
||
| func TestSetInFileIsIdempotent(t *testing.T) { | ||
| path := filepath.Join(t.TempDir(), "config.toml") | ||
| require.NoError(t, os.WriteFile(path, []byte("[[containers]]\ntype = \"aws\"\n"), 0644)) | ||
|
|
||
| require.NoError(t, setInFile(path, "cli.update_skipped_version", "v1.0.0")) | ||
| require.NoError(t, setInFile(path, "cli.update_skipped_version", "v2.0.0")) | ||
| require.NoError(t, setInFile(path, "cli.update_skipped_version", "v3.0.0")) | ||
|
|
||
| got, err := os.ReadFile(path) | ||
| require.NoError(t, err) | ||
|
|
||
| var parsed struct { | ||
| CLI struct { | ||
| UpdateSkippedVersion string `toml:"update_skipped_version"` | ||
| } `toml:"cli"` | ||
| } | ||
| require.NoError(t, toml.Unmarshal(got, &parsed)) | ||
| assert.Equal(t, "v3.0.0", parsed.CLI.UpdateSkippedVersion) | ||
|
|
||
| assert.Equal(t, 1, strings.Count(string(got), "update_skipped_version")) | ||
| } | ||
|
|
||
| func TestSetInFileErrorsOnMissingFile(t *testing.T) { | ||
| err := setInFile(filepath.Join(t.TempDir(), "nonexistent.toml"), "cli.update_skipped_version", "v1.0.0") | ||
| assert.Error(t, err) | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.