utils_test.go 933 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package download
  2. import (
  3. "os/exec"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/Jguer/yay/v10/pkg/settings/exe"
  7. )
  8. type testRunner struct{}
  9. func (t *testRunner) Capture(cmd *exec.Cmd, timeout int64) (stdout string, stderr string, err error) {
  10. return "", "", nil
  11. }
  12. func (t *testRunner) Show(cmd *exec.Cmd) error {
  13. return nil
  14. }
  15. type testGitBuilder struct {
  16. index int
  17. test *testing.T
  18. want string
  19. parentBuilder *exe.CmdBuilder
  20. }
  21. func (t *testGitBuilder) BuildGitCmd(dir string, extraArgs ...string) *exec.Cmd {
  22. cmd := t.parentBuilder.BuildGitCmd(dir, extraArgs...)
  23. assert.Equal(t.test, t.want, cmd.String())
  24. t.index += 1
  25. return cmd
  26. }
  27. func (c *testGitBuilder) Show(cmd *exec.Cmd) error {
  28. return c.parentBuilder.Show(cmd)
  29. }
  30. func (c *testGitBuilder) Capture(cmd *exec.Cmd, timeout int64) (stdout, stderr string, err error) {
  31. return c.parentBuilder.Capture(cmd, timeout)
  32. }