From 929e2d2d7cb4cb8847c729be5a6a6915191e73b4 Mon Sep 17 00:00:00 2001 From: ashish6298 Date: Tue, 22 Sep 2026 16:36:41 +0530 Subject: [PATCH] test(base): add unit tests for ChecksumOption serialization --- pkg/base/model_test.go | 32 ++++++++++++++++++++++++++++++++ pkg/download/model.go | 3 +++ 2 files changed, 35 insertions(+) diff --git a/pkg/base/model_test.go b/pkg/base/model_test.go index c0cf50f2..23ac3ac6 100644 --- a/pkg/base/model_test.go +++ b/pkg/base/model_test.go @@ -435,3 +435,35 @@ func TestDownloaderStoreConfig_Merge(t *testing.T) { }) } } + +func TestOptions_Checksum(t *testing.T) { + opts := &Options{ + Name: "test.zip", + Path: "/downloads", + Checksum: &ChecksumOption{ + Algorithm: "sha256", + Expected: "abcdef1234567890", + }, + } + + cloned := opts.Clone() + if cloned.Checksum == nil { + t.Fatal("expected cloned options to have non-nil Checksum") + } + if cloned.Checksum.Algorithm != "sha256" || cloned.Checksum.Expected != "abcdef1234567890" { + t.Fatalf("cloned checksum mismatch: got %+v", cloned.Checksum) + } + + // Verify deep clone isolation + cloned.Checksum.Expected = "modified" + if opts.Checksum.Expected != "abcdef1234567890" { + t.Fatal("modifying cloned checksum affected original options") + } + + // Verify nil checksum options clone + optsNil := &Options{Name: "nil_check.zip"} + clonedNil := optsNil.Clone() + if clonedNil.Checksum != nil { + t.Fatal("expected nil checksum in cloned options") + } +} diff --git a/pkg/download/model.go b/pkg/download/model.go index c838cf31..6d7017b7 100644 --- a/pkg/download/model.go +++ b/pkg/download/model.go @@ -23,6 +23,9 @@ type ResolveResult struct { Res *base.Resource `json:"res"` } +// Task represents a download unit. +// Options flow path: +// REST Request (model.CreateTask/ResolveTask) -> pkg/download Downloader -> Task.Meta.Opts (base.Options) -> Fetcher.Resolve/Start (e.g. internal/protocol/http/fetcher.go) type Task struct { ID string `json:"id"` Protocol string `json:"protocol"`