Repository navigation
feat(update): detect install method to tailor or suppress update notices #107
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
7 commits
Select commit
Hold shift + click to select a range
a8b3ad1
feat(update): detect install method to tailor or suppress update notices
pjcdawkins 2ea9f82
fix(update): address review of install-method update notices
pjcdawkins 61e1b66
fix(update): keep notices for quiet runs and quote the installer dir
pjcdawkins e1abdbf
fix(update): force raw installer method and harden detection
pjcdawkins e8bf4a2
fix(update): repair corrupt state and bound package queries
pjcdawkins 9097dd3
fix(update): write state atomically and bound each package query
pjcdawkins f8c20ab
fix(update): fall back to a direct state write and share the query de…
pjcdawkins 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
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,54 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/upsun/cli/internal" | ||
| ) | ||
|
|
||
| func TestUpgradeCommandFor(t *testing.T) { | ||
| cnf := testConfig() | ||
| cnf.Wrapper.HomebrewTap = "upsun/tap/upsun-cli" | ||
| cnf.Wrapper.NpmPackage = "upsun" | ||
| cnf.Wrapper.InstallerURL = "https://x.test/i.sh" | ||
| cnf.Application.Executable = "upsun" | ||
|
|
||
| cases := []struct { | ||
| method internal.InstallMethod | ||
| want string | ||
| }{ | ||
| {internal.InstallHomebrew, "brew update && brew upgrade upsun/tap/upsun-cli"}, | ||
| {internal.InstallScoop, "scoop update upsun"}, | ||
| {internal.InstallNpm, "npm install -g upsun@latest"}, | ||
| {internal.InstallScript, "curl -fsSL https://x.test/i.sh | INSTALL_METHOD=raw INSTALL_DIR=/usr/local/bin sh"}, | ||
| {internal.InstallPackage, ""}, // suppressed; no tailored command | ||
| {internal.InstallUnknown, ""}, // falls back to the generic link | ||
| } | ||
| for _, c := range cases { | ||
| t.Run(string(c.method), func(t *testing.T) { | ||
| assert.Equal(t, c.want, upgradeCommandFor(cnf, c.method, "/usr/local/bin/upsun")) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestUpgradeCommandForMissingConfigFallsBack(t *testing.T) { | ||
| cnf := testConfig() // no Wrapper.* fields set | ||
| // Homebrew/npm/script require their config field; without it, fall back (empty). | ||
| assert.Empty(t, upgradeCommandFor(cnf, internal.InstallHomebrew, "/usr/local/bin/upsun")) | ||
| assert.Empty(t, upgradeCommandFor(cnf, internal.InstallNpm, "/usr/local/bin/upsun")) | ||
| assert.Empty(t, upgradeCommandFor(cnf, internal.InstallScript, "/usr/local/bin/upsun")) | ||
| } | ||
|
|
||
| func TestShellQuote(t *testing.T) { | ||
| cases := []struct{ in, want string }{ | ||
| {"/usr/local/bin", "/usr/local/bin"}, | ||
| {"/home/Jane Doe/.local/bin", "'/home/Jane Doe/.local/bin'"}, | ||
| {"/tmp/it's", `'/tmp/it'\''s'`}, | ||
| {"/tmp/$(id)", "'/tmp/$(id)'"}, | ||
| } | ||
| for _, c := range cases { | ||
| assert.Equal(t, c.want, shellQuote(c.in)) | ||
| } | ||
| } |
Oops, something went wrong.
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.