Skip to content

Commit

Permalink
fix(webhook): fix version comparison of webhook resources (#1807)
Browse files Browse the repository at this point in the history
Signed-off-by: shubham <[email protected]>
  • Loading branch information
shubham14bajpai authored Jun 14, 2021
1 parent ec94efe commit 1c75c58
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
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)
}
})
}
}

0 comments on commit 1c75c58

Please sign in to comment.