Comments (7)
I did PR the fix @ #39.
By the way, I think I can help to cover up coverages for github.com/nao1215/gup/internal/goutil
.
I will draft PR as soon as your #38 gets merged.
from gup.
I think the modification method should be the same as the sample code.
OK! If you don't mind, I'd like to do some PR to help solve this issue.
from gup.
I merged PR #39.
By the way, I think I can help to cover up coverages for github.com/nao1215/gup/internal/goutil.
I will draft PR as soon as your #38 gets merged.
٩(。˃ ᵕ ˂ )و WRYYYYYYYYYYYYYYYYYYYYYYYYYY
Very nice suggestion!! I will merge #38 once.
from gup.
@KEINOS
Thanks for the detailed bug report. I have read the sample code you have written.
I think the modification method should be the same as the sample code.
I will find time to fix it.
(However, I may not be able to fix it faster than you expect)
from gup.
@KEINOS
My son has gone to bed. I have time to write some code.
However, you may be able to give me a PR. Therefore, today I am expanding the test code.
from gup.
Proposed fix
Even though, it is ideal to use go-semver for comparing the versions, I think the easiest fix is to use strings.Compare()
.
// IsAlreadyUpToDate return whether binary is already up to date or not.
func IsAlreadyUpToDate(ver Version) bool {
- return ver.Current == ver.Latest
+ if ver.Current == ver.Latest {
+ return true
+ }
+
+ return strings.Compare(
+ strings.TrimLeft(ver.Current, "v"),
+ strings.TrimLeft(ver.Latest, "v"),
+ ) >= 0
}
package main
import (
"strings"
"testing"
)
type Version struct {
Current string // before
Latest string // after
}
func IsAlreadyUpToDate(ver Version) bool {
if ver.Current == ver.Latest {
return true
}
return strings.Compare(
strings.TrimLeft(ver.Current, "v"),
strings.TrimLeft(ver.Latest, "v"),
) >= 0
}
func TestIsAlreadyUpToDate(t *testing.T) {
for _, test := range []struct {
curr string
latest string
expect bool
}{
// Regular cases
{curr: "v1.9.0", latest: "v1.9.1", expect: false},
{curr: "v1.9.0", latest: "v1.9.0", expect: true},
{curr: "v1.9.1", latest: "v1.9.0", expect: true},
// Irregular cases
{curr: "v1.9.1-0.20220908165354-f7355b5d2afa", latest: "v1.9.0", expect: true},
{
curr: "v0.0.0-20220913151710-7c6e287988f3",
latest: "v0.0.0-20210608161538-9736a4bde949",
expect: true,
},
{
curr: "v0.0.0-20210608161538-9736a4bde949",
latest: "v0.0.0-20220913151710-7c6e287988f3",
expect: false,
},
// Compatibility between go-style semver and pure-semver
{curr: "v1.9.0", latest: "1.9.1", expect: false},
{curr: "1.9.0", latest: "v1.9.1", expect: false},
} {
verTmp := Version{
Current: test.curr,
Latest: test.latest,
}
expect := test.expect
actual := IsAlreadyUpToDate(verTmp)
// Assert to be equal
if expect != actual {
t.Errorf("(\"%v\" >= \"%v\") = %v, want %v",
test.curr, test.latest, actual, expect)
}
}
}
- View online @ Go Playground
from gup.
OK. Then, I will PR the fix without the test!
from gup.
Related Issues (20)
- Use buildinfo (After go 1.18 is released)
- Add .goreleaser.yaml HOT 1
- error fatal: not a git repository (or any of the parent directories): .git HOT 10
- Suggestions for improvements HOT 12
- --dry-run is slower than update without --dry-run
- Don't generate shell completion files by default HOT 2
- Auto-generate PowerShell completion file
- Comments from reddit HOT 1
- [Proposal] Add platform testing in the CI (GitHub Actions) HOT 3
- Add option to disable notification HOT 5
- Pass unit tests with GitHub Actions for *BSD HOT 3
- [BUG] "@latest" vs "@master", the "latest" wins HOT 10
- question: how to set default ldflags HOT 4
- Support XDG_CONFIG_HOME for configuration files path HOT 2
- make generation of completion configurable HOT 2
- Extreme cpu and memory usage HOT 3
- [BUG Report] Ignore .DS_Store files on macOS HOT 2
- Feature Request option to ignore a binary update HOT 4
- Refactoring for upgrading to gup version 1.0.0. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gup.