From 79d9be7ee7e39c96b093ec66351eb61d3741e9bc Mon Sep 17 00:00:00 2001 From: Michael Bang Date: Wed, 3 Jul 2024 09:59:51 +0200 Subject: [PATCH] tester: Add MockWriteCloser --- internal/infrastructure/tester/writecloser.go | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 internal/infrastructure/tester/writecloser.go diff --git a/internal/infrastructure/tester/writecloser.go b/internal/infrastructure/tester/writecloser.go new file mode 100644 index 0000000..3a00ea8 --- /dev/null +++ b/internal/infrastructure/tester/writecloser.go @@ -0,0 +1,49 @@ +package tester + +import "fmt" + +type MockWriteCloser struct { + CloseMock func() error + CloseCalls []writeCloserCloseCall + + WriteMock func(p []byte) (n int, err error) + WriteCalls []writeCloserWriteCall +} + +type writeCloserCloseCall struct { + Out0 error +} + +func (_v *MockWriteCloser) Close() error { + if _v.CloseMock == nil { + msg := fmt.Sprintf("call to %T.Close, but MockClose is not set", _v) + panic(msg) + } + + _v.CloseCalls = append(_v.CloseCalls, writeCloserCloseCall{}) + out0 := _v.CloseMock() + _v.CloseCalls[len(_v.CloseCalls)-1].Out0 = out0 + return out0 +} + +type writeCloserWriteCall struct { + P []byte + + Out0 int + Out1 error +} + +func (_v *MockWriteCloser) Write(p []byte) (n int, err error) { + if _v.WriteMock == nil { + msg := fmt.Sprintf("call to %T.Write, but MockWrite is not set", _v) + panic(msg) + } + + _v.WriteCalls = append(_v.WriteCalls, writeCloserWriteCall{ + P: p, + }) + out0, out1 := _v.WriteMock(p) + _v.WriteCalls[len(_v.WriteCalls)-1].Out0 = out0 + _v.WriteCalls[len(_v.WriteCalls)-1].Out1 = out1 + return out0, out1 +}