Skip to content
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

fix: add a routable string helper to verevet.Version #401

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func (v Version) String() string {
return d
}

// RoutableString returns the string representation of the version that can used while setting up the router.
// If the version is before the DefaultPivotDate, it will return the stability in the string.
func (v Version) RoutableString() string {
if v.Date.Before(DefaultPivotDate.Date) {
return v.String()
}
return v.DateString()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this replace String? What use cases are there for using the original String method over this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The blast radius for that change would be quite a lot, the .String method is used in other contexts. We can replace the .String -> .RoutableString iteratively where needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what semantic versioning is for

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what semantic versioning is for

Dont get what you mean by that bit

Currently, there are 58 usages for version.String() in the vervet codebase and the RoutableString implementation is not valid for all of them. We might introduce a lot of unintended side-effects if we replace the String method


// AddDays returns the version corresponding to adding the given number of days
// to the version date.
func (v Version) AddDays(days int) Version {
Expand Down
51 changes: 51 additions & 0 deletions version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,54 @@ func TestVersionIndex_ResolveGAorBetaStability(t *testing.T) {
})
}
}

func TestVersion_RoutableString(t *testing.T) {
tests := []struct {
name string
v Version
want string
}{
{
name: "ga before pivot date",
v: MustParseVersion("2021-06-07"),
want: "2021-06-07",
},
{
name: "beta before pivot date",
v: MustParseVersion("2021-06-07~beta"),
want: "2021-06-07~beta",
},
{
name: "beta before pivot date",
v: MustParseVersion("2021-06-07~experimental"),
want: "2021-06-07~experimental",
},
{
name: "ga on pivot date",
v: MustParseVersion("2024-10-15"),
want: "2024-10-15",
},
{
name: "beta on pivot date",
v: MustParseVersion("2024-10-15~beta"),
want: "2024-10-15",
},
{
name: "ga after pivot date",
v: MustParseVersion("2024-11-15"),
want: "2024-11-15",
},
{
name: "beta after pivot date",
v: MustParseVersion("2024-11-15~beta"),
want: "2024-11-15",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.v.RoutableString(); got != tt.want {
t.Errorf("RoutableString() = %v, want %v", got, tt.want)
}
})
}
}