1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
package lib
import (
"bytes"
"os"
"testing"
)
func TestRegisterInputConverter(t *testing.T) {
origMap := inputConverterMap
inputConverterMap = make(map[string]InputConverter)
defer func() { inputConverterMap = origMap }()
mock := &mockInputConverter{typeName: "test-ic", action: ActionAdd, description: "Test Input"}
// Register successfully
if err := RegisterInputConverter("test-ic", mock); err != nil {
t.Errorf("RegisterInputConverter error = %v", err)
}
// Duplicate registration
if err := RegisterInputConverter("test-ic", mock); err != ErrDuplicatedConverter {
t.Errorf("expected ErrDuplicatedConverter, got %v", err)
}
}
func TestRegisterOutputConverter(t *testing.T) {
origMap := outputConverterMap
outputConverterMap = make(map[string]OutputConverter)
defer func() { outputConverterMap = origMap }()
mock := &mockOutputConverter{typeName: "test-oc", action: ActionOutput, description: "Test Output"}
// Register successfully
if err := RegisterOutputConverter("test-oc", mock); err != nil {
t.Errorf("RegisterOutputConverter error = %v", err)
}
// Duplicate registration
if err := RegisterOutputConverter("test-oc", mock); err != ErrDuplicatedConverter {
t.Errorf("expected ErrDuplicatedConverter, got %v", err)
}
}
func TestListInputConverter(t *testing.T) {
origMap := inputConverterMap
inputConverterMap = make(map[string]InputConverter)
defer func() { inputConverterMap = origMap }()
mock := &mockInputConverter{typeName: "test-ic", action: ActionAdd, description: "Test Input"}
RegisterInputConverter("test-ic", mock)
// Capture stdout
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
ListInputConverter()
w.Close()
os.Stdout = old
var buf bytes.Buffer
buf.ReadFrom(r)
output := buf.String()
expected := "All available input formats:\n - test-ic (Test Input)\n"
if output != expected {
t.Errorf("ListInputConverter output = %q, want %q", output, expected)
}
}
func TestListOutputConverter(t *testing.T) {
origMap := outputConverterMap
outputConverterMap = make(map[string]OutputConverter)
defer func() { outputConverterMap = origMap }()
mock := &mockOutputConverter{typeName: "test-oc", action: ActionOutput, description: "Test Output"}
RegisterOutputConverter("test-oc", mock)
// Capture stdout
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
ListOutputConverter()
w.Close()
os.Stdout = old
var buf bytes.Buffer
buf.ReadFrom(r)
output := buf.String()
expected := "All available output formats:\n - test-oc (Test Output)\n"
if output != expected {
t.Errorf("ListOutputConverter output = %q, want %q", output, expected)
}
}
|