Skip to content

Commit a135b83

Browse files
Merge pull request #739 from cverna/fix-coreos-regex-738
Fix regex to match new CoreOS display name format
2 parents 893f340 + 59648ec commit a135b83

2 files changed

Lines changed: 121 additions & 2 deletions

File tree

pkg/rhcos/rhcos.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ var (
3434

3535
reMdPromotedFrom = regexp.MustCompile("Promoted from (.*):(.*)")
3636

37-
reMdRHCoSDiff = regexp.MustCompile(`\* Red Hat Enterprise Linux CoreOS upgraded from ((\d+)\.[\w\.\-]+) to ((\d+)\.[\w\.\-]+)\n`)
38-
reMdRHCoSVersion = regexp.MustCompile(`\* Red Hat Enterprise Linux CoreOS ((\d+)\.[\w\.\-]+)\n`)
37+
// Handle both old format (no RHEL version) and new format (with RHEL version like "9.8")
38+
// Old: "* Red Hat Enterprise Linux CoreOS upgraded from 9.8.20260312-0 to 9.8.20260227-0"
39+
// New: "* Red Hat Enterprise Linux CoreOS 9.8 upgraded from 9.8.20260305-0 to 9.8.20260312-0"
40+
reMdRHCoSDiff = regexp.MustCompile(`\* Red Hat Enterprise Linux CoreOS(?: \d+\.\d+)? upgraded from ((\d+)\.[\w\.\-]+) to ((\d+)\.[\w\.\-]+)\n`)
41+
reMdRHCoSVersion = regexp.MustCompile(`\* Red Hat Enterprise Linux CoreOS(?: \d+\.\d+)? ((\d+)\.[\w\.\-]+)\n`)
3942

4043
reMdCentOSCoSDiff = regexp.MustCompile(`\* CentOS Stream CoreOS upgraded from ((\d+)\.[\w\.\-]+) to ((\d+)\.[\w\.\-]+)\n`)
4144
reMdCentOSCoSVersion = regexp.MustCompile(`\* CentOS Stream CoreOS ((\d+)\.[\w\.\-]+)\n`)

pkg/rhcos/rhcos_test.go

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,119 @@ func TestComputeJobState(t *testing.T) {
102102
})
103103
}
104104
}
105+
106+
func TestRHCoSDiffRegex(t *testing.T) {
107+
testCases := []struct {
108+
name string
109+
input string
110+
shouldMatch bool
111+
fromVersion string
112+
toVersion string
113+
}{
114+
{
115+
name: "Old format without RHEL version",
116+
input: "* Red Hat Enterprise Linux CoreOS upgraded from 9.8.20260312-0 to 9.8.20260227-0\n",
117+
shouldMatch: true,
118+
fromVersion: "9.8.20260312-0",
119+
toVersion: "9.8.20260227-0",
120+
},
121+
{
122+
name: "New format with RHEL version",
123+
input: "* Red Hat Enterprise Linux CoreOS 9.8 upgraded from 9.8.20260305-0 to 9.8.20260312-0\n",
124+
shouldMatch: true,
125+
fromVersion: "9.8.20260305-0",
126+
toVersion: "9.8.20260312-0",
127+
},
128+
{
129+
name: "Old format with 4.x style versions",
130+
input: "* Red Hat Enterprise Linux CoreOS upgraded from 418.94.202410090804-0 to 418.94.202410150804-0\n",
131+
shouldMatch: true,
132+
fromVersion: "418.94.202410090804-0",
133+
toVersion: "418.94.202410150804-0",
134+
},
135+
{
136+
name: "Old format without RHEL version and without 4.x style",
137+
input: "* Red Hat Enterprise Linux CoreOS upgraded from 9.6.20260225-1 to 9.6.20260303-1\n",
138+
shouldMatch: true,
139+
fromVersion: "9.6.20260225-1",
140+
toVersion: "9.6.20260303-1",
141+
},
142+
{
143+
name: "CentOS Stream CoreOS does not match RHEL CoreOS regex",
144+
input: "* CentOS Stream CoreOS upgraded from 9.6.20260225-1 to 9.6.20260303-1\n",
145+
shouldMatch: false,
146+
},
147+
}
148+
for _, tc := range testCases {
149+
t.Run(tc.name, func(t *testing.T) {
150+
matches := reMdRHCoSDiff.FindStringSubmatch(tc.input)
151+
if tc.shouldMatch {
152+
if matches == nil {
153+
t.Errorf("Expected match but got none for input: %s", tc.input)
154+
return
155+
}
156+
if matches[1] != tc.fromVersion {
157+
t.Errorf("Expected from version %q, got %q", tc.fromVersion, matches[1])
158+
}
159+
if matches[3] != tc.toVersion {
160+
t.Errorf("Expected to version %q, got %q", tc.toVersion, matches[3])
161+
}
162+
} else {
163+
if matches != nil {
164+
t.Errorf("Expected no match but got: %v", matches)
165+
}
166+
}
167+
})
168+
}
169+
}
170+
171+
func TestRHCoSVersionRegex(t *testing.T) {
172+
testCases := []struct {
173+
name string
174+
input string
175+
shouldMatch bool
176+
version string
177+
}{
178+
{
179+
name: "Old format without RHEL version",
180+
input: "* Red Hat Enterprise Linux CoreOS 9.8.20260312-0\n",
181+
shouldMatch: true,
182+
version: "9.8.20260312-0",
183+
},
184+
{
185+
name: "New format with RHEL version",
186+
input: "* Red Hat Enterprise Linux CoreOS 9.8 9.8.20260305-0\n",
187+
shouldMatch: true,
188+
version: "9.8.20260305-0",
189+
},
190+
{
191+
name: "Old format with 4.x style versions",
192+
input: "* Red Hat Enterprise Linux CoreOS 418.94.202410090804-0\n",
193+
shouldMatch: true,
194+
version: "418.94.202410090804-0",
195+
},
196+
{
197+
name: "CentOS Stream CoreOS does not match RHEL CoreOS regex",
198+
input: "* CentOS Stream CoreOS 9.8.20260312-0\n",
199+
shouldMatch: false,
200+
},
201+
}
202+
for _, tc := range testCases {
203+
t.Run(tc.name, func(t *testing.T) {
204+
matches := reMdRHCoSVersion.FindStringSubmatch(tc.input)
205+
if tc.shouldMatch {
206+
if matches == nil {
207+
t.Errorf("Expected match but got none for input: %s", tc.input)
208+
return
209+
}
210+
if matches[1] != tc.version {
211+
t.Errorf("Expected version %q, got %q", tc.version, matches[1])
212+
}
213+
} else {
214+
if matches != nil {
215+
t.Errorf("Expected no match but got: %v", matches)
216+
}
217+
}
218+
})
219+
}
220+
}

0 commit comments

Comments
 (0)