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(webhook): fix version comparison of webhook resources #1807

Merged
merged 1 commit into from
Jun 14, 2021
Merged
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
7 changes: 4 additions & 3 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,10 @@ func IsCurrentLessThanNewVersion(old, new string) bool {
for i := 0; i < len(oldVersions); i++ {
oldVersion, _ := strconv.Atoi(oldVersions[i])
newVersion, _ := strconv.Atoi(newVersions[i])
if oldVersion > newVersion {
return false
if oldVersion == newVersion {
continue
}
return oldVersion < newVersion
}
return true
return false
}
44 changes: 44 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,47 @@ func TestRemoveString(t *testing.T) {
})
}
}

func TestIsCurrentLessThanNewVersion(t *testing.T) {
type args struct {
old string
new string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "old is less than new",
args: args{
old: "1.12.0",
new: "2.8.0",
},
want: true,
},
{
name: "old is greater than new",
args: args{
old: "2.10.0-RC2",
new: "2.8.0",
},
want: false,
},
{
name: "old is same as new",
args: args{
old: "2.8.0",
new: "2.8.0",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsCurrentLessThanNewVersion(tt.args.old, tt.args.new); got != tt.want {
t.Errorf("IsCurrentLessThanNewVersion() = %v, want %v", got, tt.want)
}
})
}
}