summaryrefslogtreecommitdiff
path: root/lib/helpers_test.go
diff options
context:
space:
mode:
authoropenai-code-agent[bot] <[email protected]>2026-03-06 20:57:16 +0000
committeropenai-code-agent[bot] <[email protected]>2026-03-06 20:57:16 +0000
commitc2ca6487add435663073d714b0d5f2792f977e55 (patch)
treeec3ae30539110bb57fe8f9cbed926639256d4482 /lib/helpers_test.go
parent23a7bbf963aca608ce1344f2f1986034020ad8c3 (diff)
test: add comprehensive lib package coveragecodex/add-unit-tests-lib-package
Diffstat (limited to 'lib/helpers_test.go')
-rw-r--r--lib/helpers_test.go100
1 files changed, 100 insertions, 0 deletions
diff --git a/lib/helpers_test.go b/lib/helpers_test.go
new file mode 100644
index 00000000..2ea80692
--- /dev/null
+++ b/lib/helpers_test.go
@@ -0,0 +1,100 @@
+package lib
+
+import (
+ "bytes"
+ "io"
+ "os"
+ "testing"
+)
+
+type mockInputConverter struct {
+ typ string
+ action Action
+ desc string
+ err error
+ inputFn func(Container) (Container, error)
+}
+
+func (m mockInputConverter) GetType() string {
+ return m.typ
+}
+
+func (m mockInputConverter) GetAction() Action {
+ return m.action
+}
+
+func (m mockInputConverter) GetDescription() string {
+ if m.desc != "" {
+ return m.desc
+ }
+ return "mock input converter"
+}
+
+func (m mockInputConverter) Input(c Container) (Container, error) {
+ if m.inputFn != nil {
+ return m.inputFn(c)
+ }
+ return c, m.err
+}
+
+type mockOutputConverter struct {
+ typ string
+ action Action
+ desc string
+ err error
+ outFn func(Container) error
+}
+
+func (m mockOutputConverter) GetType() string {
+ return m.typ
+}
+
+func (m mockOutputConverter) GetAction() Action {
+ return m.action
+}
+
+func (m mockOutputConverter) GetDescription() string {
+ if m.desc != "" {
+ return m.desc
+ }
+ return "mock output converter"
+}
+
+func (m mockOutputConverter) Output(c Container) error {
+ if m.outFn != nil {
+ return m.outFn(c)
+ }
+ return m.err
+}
+
+func captureOutput(t *testing.T, fn func()) string {
+ t.Helper()
+
+ stdout := os.Stdout
+ r, w, _ := os.Pipe()
+ os.Stdout = w
+
+ fn()
+
+ _ = w.Close()
+ os.Stdout = stdout
+
+ var buf bytes.Buffer
+ _, _ = io.Copy(&buf, r)
+ _ = r.Close()
+
+ return buf.String()
+}
+
+func resetInputConverters() {
+ inputConverterMap = make(map[string]InputConverter)
+}
+
+func resetOutputConverters() {
+ outputConverterMap = make(map[string]OutputConverter)
+}
+
+func resetConfigCreators() {
+ inputConfigCreatorCache = make(map[string]inputConfigCreator)
+ outputConfigCreatorCache = make(map[string]outputConfigCreator)
+}