From 108ecaf4da0ca43f77a2df3e44c6c7a6785c75a8 Mon Sep 17 00:00:00 2001 From: zongz Date: Mon, 29 Apr 2024 14:53:08 +0800 Subject: [PATCH 1/2] fix: fix logWriter missing in KpmClient Signed-off-by: zongz --- pkg/client/client.go | 1 + pkg/client/client_test.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 43c9f3b8..3b7c6674 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -380,6 +380,7 @@ func (c *KpmClient) CompileWithOpts(opts *opt.CompileOptions) (*kcl.KCLResultLis } c.noSumCheck = opts.NoSumCheck() + c.logWriter = opts.LogWriter() kclPkg, err := c.LoadPkgFromPath(pkgPath) if err != nil { diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index ca1a6ee3..ed043390 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -1480,12 +1480,16 @@ func TestRunWithOciDownloader(t *testing.T) { kpmCli.DepDownloader = downloader.NewOciDownloader("linux/amd64") + var buf bytes.Buffer + writer := io.MultiWriter(&buf, os.Stdout) + res, err := kpmCli.RunWithOpts( opt.WithEntries([]string{filepath.Join(path, "run_pkg", "pkg", "main.k")}), opt.WithKclOption(kcl.WithWorkDir(filepath.Join(path, "run_pkg", "pkg"))), opt.WithNoSumCheck(true), - opt.WithLogWriter(nil), + opt.WithLogWriter(writer), ) assert.Equal(t, err, nil) + assert.Equal(t, buf.String(), "downloading 'zong-zhe/helloworld:0.0.3' from 'ghcr.io/zong-zhe/helloworld:0.0.3'\n") assert.Equal(t, res.GetRawYamlResult(), "The_first_kcl_program: Hello World!") } From c706ab7795d8a936238e969732e76195bf8a733f Mon Sep 17 00:00:00 2001 From: zongz Date: Mon, 29 Apr 2024 15:00:52 +0800 Subject: [PATCH 2/2] fix: make test case running in order to test the log output Signed-off-by: zongz --- pkg/client/client_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index ed043390..6cfd19a8 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -1439,7 +1439,13 @@ func TestLoadOciUrlDiffSetting(t *testing.T) { assert.Equal(t, err, nil) } -func TestAddWithOciDownloader(t *testing.T) { +func TestOciDownloader(t *testing.T) { + // make test case running in order to test the log output + testRunWithOciDownloader(t) + testAddWithOciDownloader(t) +} + +func testAddWithOciDownloader(t *testing.T) { kpmCli, err := NewKpmClient() path := getTestDir("test_oci_downloader") assert.Equal(t, err, nil) @@ -1473,7 +1479,7 @@ func TestAddWithOciDownloader(t *testing.T) { assert.Equal(t, utils.RmNewline(string(expectmodContent)), utils.RmNewline(string(gotContent))) } -func TestRunWithOciDownloader(t *testing.T) { +func testRunWithOciDownloader(t *testing.T) { kpmCli, err := NewKpmClient() path := getTestDir("test_oci_downloader") assert.Equal(t, err, nil)