Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
Fix read length reporting (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
adracus authored Apr 17, 2023
1 parent 2520e6a commit 9eaf52b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (r *readCloser) Read(data []Module) (n int, err error) {
return i, err
}
}
return 0, nil
return len(data), nil
}

func (r *readCloser) Close() error {
Expand Down
20 changes: 20 additions & 0 deletions internal/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,25 @@ var _ = Describe("Internal", func() {
Expect(n).To(Equal(3))
Expect(modules[:3]).To(Equal(testdata.Modules))
})

It("should properly chunk the command data JSON stream", func() {
cmd := func() *exec.Cmd {
return exec.Command(gocatExecutable, filepath.Join("..", "testdata", "modules.json.stream"))
}
rc, err := module.OpenGoList(&module.OpenGoListOptions{Command: cmd})
Expect(err).NotTo(HaveOccurred())
DeferCleanup(rc.Close)

modules := make([]module.Module, 4)
n, err := rc.Read(modules[:2])
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(2))

n, err = rc.Read(modules[2:4])
Expect(err).To(MatchError(io.EOF))
Expect(n).To(Equal(1))

Expect(modules[:3]).To(Equal(testdata.Modules))
})
})
})

0 comments on commit 9eaf52b

Please sign in to comment.