Skip to content

Commit 1c75c58

Browse files
fix(webhook): fix version comparison of webhook resources (#1807)
Signed-off-by: shubham <[email protected]>
1 parent ec94efe commit 1c75c58

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

pkg/util/util.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,10 @@ func IsCurrentLessThanNewVersion(old, new string) bool {
275275
for i := 0; i < len(oldVersions); i++ {
276276
oldVersion, _ := strconv.Atoi(oldVersions[i])
277277
newVersion, _ := strconv.Atoi(newVersions[i])
278-
if oldVersion > newVersion {
279-
return false
278+
if oldVersion == newVersion {
279+
continue
280280
}
281+
return oldVersion < newVersion
281282
}
282-
return true
283+
return false
283284
}

pkg/util/util_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,47 @@ func TestRemoveString(t *testing.T) {
373373
})
374374
}
375375
}
376+
377+
func TestIsCurrentLessThanNewVersion(t *testing.T) {
378+
type args struct {
379+
old string
380+
new string
381+
}
382+
tests := []struct {
383+
name string
384+
args args
385+
want bool
386+
}{
387+
{
388+
name: "old is less than new",
389+
args: args{
390+
old: "1.12.0",
391+
new: "2.8.0",
392+
},
393+
want: true,
394+
},
395+
{
396+
name: "old is greater than new",
397+
args: args{
398+
old: "2.10.0-RC2",
399+
new: "2.8.0",
400+
},
401+
want: false,
402+
},
403+
{
404+
name: "old is same as new",
405+
args: args{
406+
old: "2.8.0",
407+
new: "2.8.0",
408+
},
409+
want: false,
410+
},
411+
}
412+
for _, tt := range tests {
413+
t.Run(tt.name, func(t *testing.T) {
414+
if got := IsCurrentLessThanNewVersion(tt.args.old, tt.args.new); got != tt.want {
415+
t.Errorf("IsCurrentLessThanNewVersion() = %v, want %v", got, tt.want)
416+
}
417+
})
418+
}
419+
}

0 commit comments

Comments
 (0)