mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-02-11 21:41:46 +01:00
Adopt unit test to new API
This commit is contained in:
@@ -95,10 +95,8 @@ func (l *Level) getHealthyMetrics(m *MemoryStore, expectedMetrics []string) []st
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if degraded[metricName] {
|
|
||||||
degradedList = append(degradedList, metricName)
|
degradedList = append(degradedList, metricName)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return degradedList
|
return degradedList
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,7 +303,6 @@ func TestGetHealthyMetrics(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
selector []string
|
selector []string
|
||||||
expectedMetrics []string
|
expectedMetrics []string
|
||||||
wantMissing []string
|
|
||||||
wantDegraded []string
|
wantDegraded []string
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
@@ -311,15 +310,13 @@ func TestGetHealthyMetrics(t *testing.T) {
|
|||||||
name: "mixed health states",
|
name: "mixed health states",
|
||||||
selector: []string{"testcluster", "testnode"},
|
selector: []string{"testcluster", "testnode"},
|
||||||
expectedMetrics: []string{"load", "mem_used", "cpu_user"},
|
expectedMetrics: []string{"load", "mem_used", "cpu_user"},
|
||||||
wantMissing: []string{"cpu_user"},
|
wantDegraded: []string{"mem_used", "cpu_user"},
|
||||||
wantDegraded: []string{"mem_used"},
|
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "node not found",
|
name: "node not found",
|
||||||
selector: []string{"testcluster", "nonexistent"},
|
selector: []string{"testcluster", "nonexistent"},
|
||||||
expectedMetrics: []string{"load"},
|
expectedMetrics: []string{"load"},
|
||||||
wantMissing: nil,
|
|
||||||
wantDegraded: nil,
|
wantDegraded: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
@@ -327,7 +324,6 @@ func TestGetHealthyMetrics(t *testing.T) {
|
|||||||
name: "check only healthy metric",
|
name: "check only healthy metric",
|
||||||
selector: []string{"testcluster", "testnode"},
|
selector: []string{"testcluster", "testnode"},
|
||||||
expectedMetrics: []string{"load"},
|
expectedMetrics: []string{"load"},
|
||||||
wantMissing: []string{},
|
|
||||||
wantDegraded: []string{},
|
wantDegraded: []string{},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
@@ -335,7 +331,7 @@ func TestGetHealthyMetrics(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
missing, degraded, err := ms.GetHealthyMetrics(tt.selector, tt.expectedMetrics)
|
degraded, err := ms.GetHealthyMetrics(tt.selector, tt.expectedMetrics)
|
||||||
|
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("GetHealthyMetrics() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("GetHealthyMetrics() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
@@ -346,17 +342,6 @@ func TestGetHealthyMetrics(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check missing list
|
|
||||||
if len(missing) != len(tt.wantMissing) {
|
|
||||||
t.Errorf("GetHealthyMetrics() missing = %v, want %v", missing, tt.wantMissing)
|
|
||||||
} else {
|
|
||||||
for i, m := range tt.wantMissing {
|
|
||||||
if missing[i] != m {
|
|
||||||
t.Errorf("GetHealthyMetrics() missing[%d] = %v, want %v", i, missing[i], m)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check degraded list
|
// Check degraded list
|
||||||
if len(degraded) != len(tt.wantDegraded) {
|
if len(degraded) != len(tt.wantDegraded) {
|
||||||
t.Errorf("GetHealthyMetrics() degraded = %v, want %v", degraded, tt.wantDegraded)
|
t.Errorf("GetHealthyMetrics() degraded = %v, want %v", degraded, tt.wantDegraded)
|
||||||
|
|||||||
Reference in New Issue
Block a user