package model import ( "fmt" "testing" "modelRT/constants" ) func TestFuzzyRecommendOffsetUsesFullMatchedInput(t *testing.T) { tests := []struct { name string searchPrefix string searchInput string want int }{ { name: "zone fuzzy prefix", searchPrefix: "grid000", searchInput: "z", want: len([]rune("grid000.z")), }, { name: "level one fuzzy", searchPrefix: "", searchInput: "g", want: len([]rune("g")), }, { name: "measurement fuzzy preserves config token", searchPrefix: "grid.zone.station.nspath.comp.config", searchInput: "m", want: len([]rune("grid.zone.station.nspath.comp.config.m")), }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := fuzzyRecommendOffset(tt.searchPrefix, tt.searchInput) if got != tt.want { t.Fatalf("expected offset %d, got %d", tt.want, got) } }) } } func TestFallbackSpecificSetKey(t *testing.T) { tests := []struct { name string hierarchy constants.RecommendHierarchyType inputSlice []string want string wantOK bool }{ { name: "zone fallback uses grid specific set", hierarchy: constants.ZoneRecommendHierarchyType, inputSlice: []string{"grid000", "z"}, want: fmt.Sprintf(constants.RedisSpecGridZoneSetKey, "grid000"), wantOK: true, }, { name: "component tag fallback uses previous nspath token", hierarchy: constants.CompTagRecommendHierarchyType, inputSlice: []string{"grid000", "I"}, want: fmt.Sprintf(constants.RedisSpecCompNSPathCompTagSetKey, "grid000"), wantOK: true, }, { name: "measurement fallback skips config token and uses component tag", hierarchy: constants.MeasTagRecommendHierarchyType, inputSlice: []string{"nspath", "comp_tag", "config", "m"}, want: fmt.Sprintf(constants.RedisSpecCompTagMeasSetKey, "comp_tag"), wantOK: true, }, { name: "config fallback has no parent specific set", hierarchy: constants.ConfigRecommendHierarchyType, inputSlice: []string{"nspath", "comp_tag", ""}, wantOK: false, }, { name: "missing previous token", hierarchy: constants.ZoneRecommendHierarchyType, inputSlice: []string{"z"}, wantOK: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, ok := fallbackSpecificSetKey(tt.hierarchy, tt.inputSlice) if ok != tt.wantOK { t.Fatalf("expected ok %t, got %t", tt.wantOK, ok) } if got != tt.want { t.Fatalf("expected key %q, got %q", tt.want, got) } }) } }