fetch_ml/tests/unit/errors/errors_test.go
Jeremie Fraeys ea15af1833 Fix multi-user authentication and clean up debug code
- Fix YAML tags in auth config struct (json -> yaml)
- Update CLI configs to use pre-hashed API keys
- Remove double hashing in WebSocket client
- Fix port mapping (9102 -> 9103) in CLI commands
- Update permission keys to use jobs:read, jobs:create, etc.
- Clean up all debug logging from CLI and server
- All user roles now authenticate correctly:
  * Admin: Can queue jobs and see all jobs
  * Researcher: Can queue jobs and see own jobs
  * Analyst: Can see status (read-only access)

Multi-user authentication is now fully functional.
2025-12-06 12:35:32 -05:00

46 lines
1.1 KiB
Go

package tests
import (
"errors"
"strings"
"testing"
fetchErrors "github.com/jfraeys/fetch_ml/internal/errtypes"
)
func TestDataFetchErrorFormattingAndUnwrap(t *testing.T) {
underlying := errors.New("disk failure")
dfErr := &fetchErrors.DataFetchError{
Dataset: "imagenet",
JobName: "resnet",
Err: underlying,
}
msg := dfErr.Error()
if !strings.Contains(msg, "imagenet") || !strings.Contains(msg, "resnet") {
t.Fatalf("error message missing context: %s", msg)
}
if !errors.Is(dfErr, underlying) {
t.Fatalf("expected DataFetchError to unwrap to underlying error")
}
}
func TestTaskExecutionErrorFormattingAndUnwrap(t *testing.T) {
underlying := errors.New("segfault")
taskErr := &fetchErrors.TaskExecutionError{
TaskID: "1234567890",
JobName: "bert",
Phase: "execution",
Err: underlying,
}
msg := taskErr.Error()
if !strings.Contains(msg, "12345678") || !strings.Contains(msg, "bert") || !strings.Contains(msg, "execution") {
t.Fatalf("error message missing context: %s", msg)
}
if !errors.Is(taskErr, underlying) {
t.Fatalf("expected TaskExecutionError to unwrap to underlying error")
}
}