MCPcopy
hub / github.com/SurgeDM/Surge / TestStartDownload_UsesModelEnqueueContext

Function TestStartDownload_UsesModelEnqueueContext

internal/tui/update_test.go:690–733  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

688}
689
690func TestStartDownload_UsesModelEnqueueContext(t *testing.T) {
691 svc := core.NewLocalDownloadServiceWithInput(nil, nil)
692 t.Cleanup(func() {
693 _ = svc.Shutdown()
694 })
695
696 ctx, cancel := context.WithCancel(context.Background())
697 cancel()
698
699 orchestrator := processing.NewLifecycleManager(
700 func(string, string, string, []string, map[string]string, bool, int64, bool) (string, error) {
701 t.Fatal("enqueue dispatch should not run after context cancellation")
702 return "", nil
703 },
704 nil,
705 )
706
707 m := RootModel{
708 Settings: config.DefaultSettings(),
709 Service: svc,
710 Orchestrator: orchestrator,
711 enqueueCtx: ctx,
712 cancelEnqueue: func() {},
713 list: NewDownloadList(80, 20),
714 logViewport: viewport.New(viewport.WithWidth(40), viewport.WithHeight(5)),
715 }
716
717 updated, cmd := m.startDownload("https://example.com/file.bin", nil, nil, t.TempDir(), false, "file.bin", "")
718 if cmd == nil {
719 t.Fatal("expected enqueue command")
720 }
721 if len(updated.downloads) != 1 {
722 t.Fatalf("expected optimistic queued download, got %d", len(updated.downloads))
723 }
724
725 msg := cmd()
726 errMsg, ok := msg.(enqueueErrorMsg)
727 if !ok {
728 t.Fatalf("msg = %T, want enqueueErrorMsg", msg)
729 }
730 if !errors.Is(errMsg.err, context.Canceled) {
731 t.Fatalf("err = %v, want context canceled", errMsg.err)
732 }
733}
734
735func TestStartDownload_GuessesFilenameOptimisticallyWhenProvidedOrInferred(t *testing.T) {
736 svc := core.NewLocalDownloadServiceWithInput(nil, nil)

Callers

nothing calls this directly

Calls 6

startDownloadMethod · 0.95
NewLifecycleManagerFunction · 0.92
DefaultSettingsFunction · 0.92
NewDownloadListFunction · 0.85
ShutdownMethod · 0.65

Tested by

no test coverage detected