Git Product home page Git Product logo

Comments (7)

KEINOS avatar KEINOS commented on July 16, 2024 3

@nao1215

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.

KEINOS avatar KEINOS commented on July 16, 2024 2

@nao1215

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.

nao1215 avatar nao1215 commented on July 16, 2024 2

@KEINOS

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.

nao1215 avatar nao1215 commented on July 16, 2024 1

@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.

nao1215 avatar nao1215 commented on July 16, 2024 1

@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.

KEINOS avatar KEINOS commented on July 16, 2024

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)
		}
	}
}

from gup.

KEINOS avatar KEINOS commented on July 16, 2024

OK. Then, I will PR the fix without the test!

from gup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.