test(tools): add unit tests for error handling functions
* Implement tests for error functions like errRequiredField, errInvalidField, and errEntityNotFound. * Ensure proper metadata is returned for various error scenarios. * Validate error handling in CRM, Files, and other tools. * Introduce tests for parsing stored file IDs and UUIDs. * Enhance coverage for helper functions related to project resolution and session management.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package tools
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestDecodeBase64AcceptsWhitespaceAndMultipleVariants(t *testing.T) {
|
||||
tests := []struct {
|
||||
@@ -27,3 +31,45 @@ func TestDecodeBase64AcceptsWhitespaceAndMultipleVariants(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseStoredFileIDAcceptsUUIDAndURI(t *testing.T) {
|
||||
id := uuid.New()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want uuid.UUID
|
||||
}{
|
||||
{name: "bare uuid", input: id.String(), want: id},
|
||||
{name: "resource uri", input: fileURIPrefix + id.String(), want: id},
|
||||
{name: "resource uri with surrounding whitespace", input: " " + fileURIPrefix + id.String() + " ", want: id},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := parseStoredFileID(tc.input)
|
||||
if err != nil {
|
||||
t.Fatalf("parseStoredFileID(%q) error = %v", tc.input, err)
|
||||
}
|
||||
if got != tc.want {
|
||||
t.Fatalf("parseStoredFileID(%q) = %v, want %v", tc.input, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseStoredFileIDRejectsInvalidValues(t *testing.T) {
|
||||
tests := []string{
|
||||
"",
|
||||
"not-a-uuid",
|
||||
fileURIPrefix + "not-a-uuid",
|
||||
}
|
||||
|
||||
for _, input := range tests {
|
||||
t.Run(input, func(t *testing.T) {
|
||||
if _, err := parseStoredFileID(input); err == nil {
|
||||
t.Fatalf("parseStoredFileID(%q) = nil error, want error", input)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user