1
+ package org .jfrog .build .extractor .go .extractor ;
2
+
3
+
4
+ import org .jfrog .build .api .util .Log ;
5
+ import org .jfrog .build .api .util .NullLog ;
6
+ import org .testng .annotations .Test ;
7
+
8
+ import static org .testng .AssertJUnit .*;
9
+
10
+ public class GoVersionUtilsTest {
11
+
12
+ @ Test
13
+ public void getMajorVersion_ValidVersion_ReturnsMajorVersion () {
14
+ Log log = new NullLog ();
15
+ assertEquals (GoVersionUtils .getMajorVersion ("v0.0.4" , log ), 0 );
16
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.2.3" , log ), 1 );
17
+ assertEquals (GoVersionUtils .getMajorVersion ("v2.2.3" , log ), 2 );
18
+ assertEquals (GoVersionUtils .getMajorVersion ("v10.20.30" , log ), 10 );
19
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.1.2-prerelease+meta" , log ), 1 );
20
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.1.2+meta" , log ), 1 );
21
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.0.0-alpha" , log ), 1 );
22
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.0.0-alpha.beta" , log ), 1 );
23
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.0.0-alpha.1" , log ), 1 );
24
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.0.0-alpha.0valid" , log ), 1 );
25
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.0.0-rc.1+build.1" , log ), 1 );
26
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.2.3-beta" , log ), 1 );
27
+ assertEquals (GoVersionUtils .getMajorVersion ("v10.2.3-DEV-SNAPSHOT" , log ), 10 );
28
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.2.3-SNAPSHOT-123" , log ), 1 );
29
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.0.0" , log ), 1 );
30
+ assertEquals (GoVersionUtils .getMajorVersion ("v2.0.0+build.1848" , log ), 2 );
31
+ assertEquals (GoVersionUtils .getMajorVersion ("v2.0.1-alpha.1227" , log ), 2 );
32
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.0.0-alpha+beta" , log ), 1 );
33
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.2.3----RC-SNAPSHOT.12.9.1--.12+788" , log ), 1 );
34
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.2.3----R-S.12.9.1--.12+meta" , log ), 1 );
35
+ assertEquals (GoVersionUtils .getMajorVersion ("v2.2.0-beta.1" , log ), 2 );
36
+ }
37
+
38
+ @ Test
39
+ public void getMajorVersion_InvalidVersion_ReturnsZero () {
40
+ Log log = new NullLog ();
41
+ assertEquals (GoVersionUtils .getMajorVersion ("invalid.version" , log ), 0 );
42
+ assertEquals (GoVersionUtils .getMajorVersion ("" , log ), 0 );
43
+ assertEquals (GoVersionUtils .getMajorVersion (null , log ), 0 );
44
+ assertEquals (GoVersionUtils .getMajorVersion ("v01.1.1" , log ), 0 );
45
+ assertEquals (GoVersionUtils .getMajorVersion ("v9.8.7-whatever+meta+meta" , log ), 0 );
46
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.2.3.DEV" , log ), 0 );
47
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.2.3-0123" , log ), 0 );
48
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.0.0-alpha_beta" , log ), 0 );
49
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.2-SNAPSHOT" , log ), 0 );
50
+ assertEquals (GoVersionUtils .getMajorVersion ("v1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788" , log ), 0 );
51
+ }
52
+
53
+ @ Test
54
+ public void getMajorProjectVersion_ValidProject_ReturnsMajorVersion () {
55
+ Log log = new NullLog ();
56
+ assertEquals (GoVersionUtils .getMajorProjectVersion ("github.com/owner/repo/v3" , log ), 3 );
57
+ assertEquals (GoVersionUtils .getMajorProjectVersion ("github.com/owner/repo/v2" , log ), 2 );
58
+ }
59
+
60
+ @ Test
61
+ public void getMajorProjectVersion_InvalidProject_ReturnsZeroOrOne () {
62
+ Log log = new NullLog ();
63
+ assertEquals (GoVersionUtils .getMajorProjectVersion ("github.com/owner/repo" , log ), 0 );
64
+ assertEquals (GoVersionUtils .getMajorProjectVersion ("" , log ), 0 );
65
+ assertEquals (GoVersionUtils .getMajorProjectVersion (null , log ), 0 );
66
+ }
67
+
68
+ @ Test
69
+ public void getCleanVersion_WithIncompatible_ReturnsCleanVersion () {
70
+ assertEquals (GoVersionUtils .getCleanVersion ("1.2.3+incompatible" ), "1.2.3" );
71
+ }
72
+
73
+ @ Test
74
+ public void getCleanVersion_WithoutIncompatible_ReturnsSameVersion () {
75
+ assertEquals (GoVersionUtils .getCleanVersion ("1.2.3" ), "1.2.3" );
76
+ }
77
+
78
+ @ Test
79
+ public void isCompatibleGoModuleNaming_ValidInputs_ReturnsTrue () {
80
+ Log log = new NullLog ();
81
+ assertTrue (GoVersionUtils .isCompatibleGoModuleNaming ("github.com/owner/repo/v2" , "v2.0.5" , log ));
82
+ assertTrue (GoVersionUtils .isCompatibleGoModuleNaming ("github.com/owner/repo" , "v1.0.5" , log ));
83
+ }
84
+
85
+ @ Test
86
+ public void isCompatibleGoModuleNaming_InvalidInputs_ReturnsFalse () {
87
+ Log log = new NullLog ();
88
+ assertFalse (GoVersionUtils .isCompatibleGoModuleNaming ("github.com/owner/repo" , "v2.0.5" , log ));
89
+ assertFalse (GoVersionUtils .isCompatibleGoModuleNaming ("github.com/owner/repo/v2" , "v2.0.5+incompatible" , log ));
90
+ }
91
+
92
+ @ Test
93
+ public void getSubModule_ValidProjectName_ReturnsSubModule () {
94
+ assertEquals (GoVersionUtils .getSubModule ("github.com/owner/repo/submodule" ), "submodule" );
95
+ }
96
+
97
+ @ Test
98
+ public void getSubModule_InvalidProjectName_ReturnsEmptyString () {
99
+ assertEquals (GoVersionUtils .getSubModule ("github.com/owner/repo" ), "" );
100
+ assertEquals (GoVersionUtils .getSubModule ("" ), "" );
101
+ assertEquals (GoVersionUtils .getSubModule (null ), "" );
102
+ }
103
+
104
+ @ Test
105
+ public void getParent_ValidPath_ReturnsParentPath () {
106
+ assertEquals (GoVersionUtils .getParent ("/path/to/file" ), "/path/to" );
107
+ }
108
+
109
+ @ Test
110
+ public void getParent_InvalidPath_ReturnsEmptyString () {
111
+ assertEquals (GoVersionUtils .getParent ("" ), "" );
112
+ assertEquals (GoVersionUtils .getParent (null ), "" );
113
+ }
114
+
115
+ @ Test
116
+ public void getMajorVersion () {
117
+ Log log = new NullLog ();
118
+ assertEquals (GoVersionUtils .getMajorVersion ("" , log ), 0 );
119
+ assertEquals (GoVersionUtils .getMajorVersion (null , log ), 0 );
120
+ assertEquals (GoVersionUtils .getMajorVersion ("vX.1.2" , log ), 0 );
121
+ }
122
+
123
+ @ Test
124
+ public void getMajorProjectVersion_InvalidMajorVersion_LogsErrorAndReturnsZero () {
125
+ Log log = new NullLog ();
126
+ assertEquals (GoVersionUtils .getMajorProjectVersion ("github.com/owner/repo/vX" , log ), 0 );
127
+ }
128
+
129
+ @ Test
130
+ public void getCleanVersion_NullVersion_ReturnsNull () {
131
+ assertNull (GoVersionUtils .getCleanVersion (null ));
132
+ }
133
+
134
+ @ Test
135
+ public void isCompatibleGoModuleNaming_EmptyProjectName_ReturnsFalse () {
136
+ Log log = new NullLog ();
137
+ assertFalse (GoVersionUtils .isCompatibleGoModuleNaming ("" , "v2.0.5" , log ));
138
+ }
139
+
140
+ @ Test
141
+ public void isCompatibleGoModuleNaming_EmptyVersion_ReturnsFalse () {
142
+ Log log = new NullLog ();
143
+ assertFalse (GoVersionUtils .isCompatibleGoModuleNaming ("github.com/owner/repo/v2" , "" , log ));
144
+ }
145
+
146
+ @ Test
147
+ public void isCompatibleGoModuleNaming_NullProjectName_ReturnsFalse () {
148
+ Log log = new NullLog ();
149
+ assertFalse (GoVersionUtils .isCompatibleGoModuleNaming (null , "v2.0.5" , log ));
150
+ }
151
+
152
+ @ Test
153
+ public void isCompatibleGoModuleNaming_NullVersion_ReturnsFalse () {
154
+ Log log = new NullLog ();
155
+ assertFalse (GoVersionUtils .isCompatibleGoModuleNaming ("github.com/owner/repo/v2" , null , log ));
156
+ }
157
+
158
+ @ Test
159
+ public void getSubModule_EmptyProjectName_ReturnsEmptyString () {
160
+ assertEquals (GoVersionUtils .getSubModule ("" ), "" );
161
+ }
162
+
163
+ @ Test
164
+ public void getSubModule_NullProjectName_ReturnsEmptyString () {
165
+ assertEquals (GoVersionUtils .getSubModule (null ), "" );
166
+ }
167
+
168
+ @ Test
169
+ public void getParent_EmptyPath_ReturnsEmptyString () {
170
+ assertEquals (GoVersionUtils .getParent ("" ), "" );
171
+ }
172
+
173
+ @ Test
174
+ public void getParent_NullPath_ReturnsEmptyString () {
175
+ assertEquals (GoVersionUtils .getParent (null ), "" );
176
+ }
177
+
178
+ }
0 commit comments