Skip to content

Commit

Permalink
Merge pull request #308 from zong-zhe/fix-log-bug
Browse files Browse the repository at this point in the history
fix: fix logWriter missing in KpmClient
  • Loading branch information
Peefy authored Apr 29, 2024
2 parents f3e75d9 + c706ab7 commit 0d47303
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 13 additions & 3 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1473,19 +1479,23 @@ 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)

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!")
}

0 comments on commit 0d47303

Please sign in to comment.