Skip to content

Commit

Permalink
Attempt to resolve #139 (#140)
Browse files Browse the repository at this point in the history
* Attempt to resolve #139

* A better approach to #139 than the prior patch.

Copying the use of re.FindStringSubmatch without
a thorough understanding will backfire sooner or later.

Thank @mendesrawr for the opportunity to learn.
  • Loading branch information
KacperPerschke authored Apr 21, 2024
1 parent b9c0dbb commit 2850302
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions collector/converter_internals.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ func extractNamedGroups(artiNum string, re *regexp.Regexp) reCaptureGroups {
match := re.FindStringSubmatch(artiNum)
groupsFound := make(reCaptureGroups)
for i, name := range re.SubexpNames() {
if i != 0 && name != "" {
groupsFound[name] = match[i]
groupCaptured := match[i]
if i != 0 && name != `` && groupCaptured != `` {
groupsFound[name] = groupCaptured
}
}
return groupsFound
Expand Down
20 changes: 20 additions & 0 deletions collector/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ func TestConvNum(t *testing.T) {
input: `888.88 GB`,
want: 954427632517.119995,
},
{
// Covers https://github.com/peimanja/artifactory_exporter/issues/139
input: `1`,
want: 1.0,
},
{
// Covers https://github.com/peimanja/artifactory_exporter/issues/139
input: `44`,
want: 44.0,
},
{
// Just to check https://github.com/peimanja/artifactory_exporter/issues/139
input: `100 %`,
want: 1.0,
},
}
for _, tc := range tests {
got, err := fakeExporter.convArtiToPromNumber(tc.input)
Expand Down Expand Up @@ -94,6 +109,11 @@ func TestConvFileStoreData(t *testing.T) {
input: `494.94 GB (99.04%)`,
want: []float64{531437778370.559998, 0.9904},
},
{
// Just to check https://github.com/peimanja/artifactory_exporter/issues/139
input: `1.0 GB (1.0%)`,
want: []float64{1073741824.000000, 0.0100},
},
}
for _, tc := range tests {
gotSize, gotPercent, err := fakeExporter.convArtiToPromFileStoreData(tc.input)
Expand Down

0 comments on commit 2850302

Please sign in to comment.