summaryrefslogtreecommitdiffstats
path: root/internal/utils/version_test.go
blob: dc1627df2b3c88bfada6c95f6c7cd5a20b5c9b19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package utils

import "testing"

func TestIsNewerVersion(t *testing.T) {
	tests := []struct {
		name     string
		remote   string
		local    string
		expected bool
	}{
		{
			name:     "newer version available",
			remote:   "v0.2.0",
			local:    "v0.1.0",
			expected: true,
		},
		{
			name:     "same version",
			remote:   "v0.1.0",
			local:    "v0.1.0",
			expected: false,
		},
		{
			name:     "local is newer",
			remote:   "v0.1.0",
			local:    "v0.2.0",
			expected: false,
		},
		{
			name:     "without v prefix",
			remote:   "0.2.0",
			local:    "0.1.0",
			expected: true,
		},
		{
			name:     "mixed prefix",
			remote:   "v0.2.0",
			local:    "0.1.0",
			expected: true,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result := isNewerVersion(tt.remote, tt.local)
			if result != tt.expected {
				t.Errorf("isNewerVersion(%s, %s) = %v, expected %v", tt.remote, tt.local, result, tt.expected)
			}
		})
	}
}