iop/apps/node/internal/adapters/cli/cancel_reason_test.go

42 lines
1,007 B
Go

package cli
import (
"context"
"io"
"testing"
)
func TestCancelEventForContext_DeadlineMapsToTimeout(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 0)
defer cancel()
<-ctx.Done()
got := cancelEventForContext(ctx.Err())
if got != "timeout" {
t.Fatalf("expected 'timeout', got %q", got)
}
}
func TestCancelEventForContext_CanceledMapsToUserCancel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
<-ctx.Done()
got := cancelEventForContext(ctx.Err())
if got != "user-cancel" {
t.Fatalf("expected 'user-cancel', got %q", got)
}
}
func TestCancelEventForContext_NilError(t *testing.T) {
got := cancelEventForContext(nil)
if got != "context-done" {
t.Fatalf("expected 'context-done', got %q", got)
}
}
func TestCancelEventForContext_SiblingError(t *testing.T) {
type customErr struct{ error }
got := cancelEventForContext(customErr{io.EOF})
if got != "context-done" {
t.Fatalf("expected 'context-done', got %q", got)
}
}