Skip to content

Commit a98647f

Browse files
authored
Merge pull request #330 from SUSE/sap-do-not-add-repetead-workloads
collectors/sap: Don't repeat workloads
2 parents 0cc3737 + 3347776 commit a98647f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

internal/collectors/sap.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55
"path"
66
"regexp"
7+
"slices"
78

89
"github.com/SUSE/connect-ng/internal/util"
910
)
@@ -26,10 +27,13 @@ func getMatchedSubdirectories(absolutePath string, matcher *regexp.Regexp) ([]st
2627
}
2728
match := []string{}
2829
for _, subDirectory := range subDirectories {
30+
2931
// filter for nil values from FindStringSubmatch
3032
matches := matcher.FindStringSubmatch(subDirectory.Name())
3133
if len(matches) >= 2 {
32-
match = append(match, matches[1])
34+
if !slices.Contains(match, matches[1]) {
35+
match = append(match, matches[1])
36+
}
3337
}
3438
}
3539
return match, nil

internal/collectors/sap_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,27 @@ func TestSAPRunWithMultipleWorkloads(t *testing.T) {
153153
assert.Equal(expected, res, "Result mismatch when there are workloads")
154154
}
155155

156+
func TestSAPRunWithDuplicatedWorkloads(t *testing.T) {
157+
assert := assert.New(t)
158+
sap := SAP{}
159+
expected := Result{"sap": []map[string]interface{}{
160+
{
161+
"system_id": "DEV",
162+
"instance_types": []string{"ASCS", "J"},
163+
},
164+
}}
165+
166+
mockUtilFileExists(true)
167+
mockLocalOsReaddir(map[string][]string{
168+
"/usr/sap": []string{"DEV", ".config"},
169+
"/usr/sap/DEV": []string{"ASCS01", "ASCS01", "J01"}, // NOTE: duplicated!
170+
})
171+
172+
res, err := sap.run(ARCHITECTURE_X86_64)
173+
assert.NoError(err)
174+
assert.Equal(expected, res, "Result mismatch when there are workloads")
175+
}
176+
156177
func TestSAPRunWithNoWorkloadDetected(t *testing.T) {
157178
assert := assert.New(t)
158179
sap := SAP{}

0 commit comments

Comments
 (0)