| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package ddsnmp |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "sort" |
| 8 | "testing" |
| 9 | |
| 10 | "github.com/stretchr/testify/assert" |
| 11 | ) |
| 12 | |
| 13 | func TestSharedMappingsCompleteness(t *testing.T) { |
| 14 | // Verify all ifType entries have a corresponding group |
| 15 | missingGroups := []string{} |
| 16 | |
| 17 | for ifTypeID := range sharedMappings.ifType { |
| 18 | if _, exists := sharedMappings.ifTypeGroup[ifTypeID]; !exists { |
| 19 | missingGroups = append(missingGroups, fmt.Sprintf("%s (%s)", ifTypeID, sharedMappings.ifType[ifTypeID])) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | assert.Empty(t, missingGroups, "All interface types should have groups") |
| 24 | if len(missingGroups) == 0 { |
| 25 | t.Logf("✓ All %d interface types have groups", len(sharedMappings.ifType)) |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | func TestSharedMappingsCount(t *testing.T) { |
| 30 | t.Logf("ifType entries: %d", len(sharedMappings.ifType)) |
| 31 | t.Logf("ifTypeGroup entries: %d", len(sharedMappings.ifTypeGroup)) |
| 32 | |
| 33 | // Count items per group |
| 34 | groups := make(map[string]int) |
| 35 | for _, group := range sharedMappings.ifTypeGroup { |
| 36 | groups[group]++ |
| 37 | } |
| 38 | |
| 39 | // Sort by count descending |
| 40 | type groupCount struct { |
| 41 | name string |
| 42 | count int |
| 43 | } |
| 44 | var sorted []groupCount |
| 45 | for name, count := range groups { |
| 46 | sorted = append(sorted, groupCount{name, count}) |
| 47 | } |
| 48 | sort.Slice(sorted, func(i, j int) bool { |
| 49 | return sorted[i].count > sorted[j].count |
| 50 | }) |
| 51 | |
| 52 | t.Logf("\nGroup distribution (%d groups):", len(groups)) |
| 53 | for _, gc := range sorted { |
| 54 | t.Logf(" %3d %s", gc.count, gc.name) |
| 55 | } |
| 56 | |
| 57 | // Verify group count doesn't exceed ifType count |
| 58 | assert.LessOrEqual(t, len(sharedMappings.ifTypeGroup), len(sharedMappings.ifType), |
| 59 | "ifTypeGroup should not have more entries than ifType") |
| 60 | } |