Files
signoz/pkg/errors/suggestions_test.go
Tushar Vats 1700ad06e6 chore: refactor error response + normalize ClickHouse telemetrystore errors (#11740)
* chore: mark required and nullable in json tag, renamed methods, and added more functionality

* fix: unit test

* fix: cast clickhouse exceptions

* fix: go mod tidy

* fix: telemetrystore now returns explicit base errors

* fix: typo

* fix: added all changes

* fix: added nil check

* fix: update test files

* fix: addressed comments

* fix: change errors and suggestions to be non-nullable
2026-06-26 13:44:38 +00:00

34 lines
1.1 KiB
Go

package errors
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewValidReferences(t *testing.T) {
// An empty set returns "" so callers don't surface a bare "valid <noun> are".
assert.Equal(t, "", NewValidReferences[string](NounFields))
// The noun phrases the list, e.g. "valid fields are", "valid keys are".
assert.Equal(t, "valid fields are `a`, `b`", NewValidReferences(NounFields, "a", "b"))
assert.Equal(t, "valid keys are `a`, `b`", NewValidReferences(NounKeys, "a", "b"))
}
func TestNewSuggestionsOnLevenshteinDistance(t *testing.T) {
// No valid inputs => no suggestions at all (no bare "valid <noun> are").
assert.Empty(t, NewSuggestionsOnLevenshteinDistance("foo", NounFields, nil))
// Close match => did-you-mean plus the valid-references list.
assert.Equal(t,
[]string{"did you mean: `name`", "valid fields are `name`, `color`"},
NewSuggestionsOnLevenshteinDistance("nam", NounFields, []string{"name", "color"}),
)
// No close match => valid-references list only.
assert.Equal(t,
[]string{"valid fields are `name`, `color`"},
NewSuggestionsOnLevenshteinDistance("zzzzz", NounFields, []string{"name", "color"}),
)
}