From bf1256f1425388d1ff74ccb4fc00301e875d0c2e Mon Sep 17 00:00:00 2001 From: zongz Date: Mon, 11 Nov 2024 23:11:57 +0800 Subject: [PATCH] fix: add unit test case Signed-off-by: zongz --- pkg/visitor/visitor_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/visitor/visitor_test.go b/pkg/visitor/visitor_test.go index 0f690311..bc4b289b 100644 --- a/pkg/visitor/visitor_test.go +++ b/pkg/visitor/visitor_test.go @@ -125,3 +125,29 @@ func TestVisitedSpace(t *testing.T) { }) assert.NilError(t, err) } + +func TestVisitedPkgWithDefaultVersion(t *testing.T) { + var buf bytes.Buffer + remotePkgVisitor := RemoteVisitor{ + PkgVisitor: &PkgVisitor{ + LogWriter: &buf, + Settings: settings.GetSettings(), + }, + Downloader: &downloader.DepDownloader{}, + } + + buf.Reset() + source, err := downloader.NewSourceFromStr("oci://ghcr.io/kcl-lang/helloworld") + if err != nil { + t.Fatal(err) + } + + source.ModSpec = &downloader.ModSpec{ + Name: "subhelloworld", + } + + err = remotePkgVisitor.Visit(source, func(pkg *pkg.KclPkg) error { return nil }) + assert.Equal(t, source.ModSpec.Version, "0.0.1") + assert.Equal(t, source.Oci.Tag, "0.1.4") + assert.NilError(t, err) +}