diff options
author | Max Jonas Werner <mail@makk.es> | 2023-10-07 00:02:01 +0200 |
---|---|---|
committer | Max Jonas Werner <mail@makk.es> | 2023-10-12 11:26:36 +0200 |
commit | 129b709887b4528ced42c8d74f4c2609800a8942 (patch) | |
tree | df965cf99f0ae91b3ea662690fb17c8f672fd58d /plumbing/transport/internal/common/mocks.go | |
parent | 19fe126d8889134e6224717a756745eed9985e22 (diff) | |
download | go-git-129b709887b4528ced42c8d74f4c2609800a8942.tar.gz |
plumbing: transport/common, Improve handling of remote errors
Instead of simply returning the first line that the remote returned,
go-git now actively searches all of stderr for lines that may contain
a more actionable error message and returns that.
In addition, this change adds a case to map the GitLab-specific error
message to an ErrRepositoryNotFound error.
Signed-off-by: Max Jonas Werner <mail@makk.es>
Diffstat (limited to 'plumbing/transport/internal/common/mocks.go')
-rw-r--r-- | plumbing/transport/internal/common/mocks.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/plumbing/transport/internal/common/mocks.go b/plumbing/transport/internal/common/mocks.go new file mode 100644 index 0000000..bc18b27 --- /dev/null +++ b/plumbing/transport/internal/common/mocks.go @@ -0,0 +1,46 @@ +package common + +import ( + "bytes" + "io" + + gogitioutil "github.com/go-git/go-git/v5/utils/ioutil" + + "github.com/go-git/go-git/v5/plumbing/transport" +) + +type MockCommand struct { + stdin bytes.Buffer + stdout bytes.Buffer + stderr bytes.Buffer +} + +func (c MockCommand) StderrPipe() (io.Reader, error) { + return &c.stderr, nil +} + +func (c MockCommand) StdinPipe() (io.WriteCloser, error) { + return gogitioutil.WriteNopCloser(&c.stdin), nil +} + +func (c MockCommand) StdoutPipe() (io.Reader, error) { + return &c.stdout, nil +} + +func (c MockCommand) Start() error { + return nil +} + +func (c MockCommand) Close() error { + panic("not implemented") +} + +type MockCommander struct { + stderr string +} + +func (c MockCommander) Command(cmd string, ep *transport.Endpoint, auth transport.AuthMethod) (Command, error) { + return &MockCommand{ + stderr: *bytes.NewBufferString(c.stderr), + }, nil +} |