loader revisited

This commit is contained in:
Ilia Denisov
2026-03-16 19:52:02 +02:00
committed by GitHub
parent e6c6970947
commit 3f1776aa5f
30 changed files with 1581 additions and 527 deletions
+39
View File
@@ -0,0 +1,39 @@
package client
import (
"errors"
"testing"
gerr "galaxy/error"
"github.com/stretchr/testify/require"
)
func TestHandlerErrorDispatchesByClass(t *testing.T) {
t.Parallel()
tests := []struct {
name string
err error
wantEvent string
}{
{name: "connection", err: gerr.WrapConnection(errors.New("dial")), wantEvent: "connection"},
{name: "storage", err: gerr.WrapStorage(errors.New("write file")), wantEvent: "storage"},
{name: "service", err: gerr.WrapService(errors.New("bad response")), wantEvent: "service"},
{name: "unclassified defaults to service", err: errors.New("plain"), wantEvent: "service"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var got string
c := &client{
onConnectionErrFn: func(error) { got = "connection" },
onStorageErrFn: func(error) { got = "storage" },
onServiceErrFn: func(error) { got = "service" },
}
c.handlerError(tt.err)
require.Equal(t, tt.wantEvent, got)
})
}
}