MCPcopy
hub / github.com/marmotedu/iam / TestMaxWidthWriter

Function TestMaxWidthWriter

internal/iamctl/util/term/term_writer_test.go:58–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestMaxWidthWriter(t *testing.T) {
59 testcases := map[string]struct {
60 input string
61 maxWidth uint
62 }{
63 "max 10": {input: test, maxWidth: 10},
64 "max 80": {input: test, maxWidth: 80},
65 "max 120": {input: test, maxWidth: 120},
66 "max 5000": {input: test, maxWidth: 5000},
67 }
68 for k, tc := range testcases {
69 b := bytes.NewBufferString("")
70 w := NewMaxWidthWriter(b, tc.maxWidth)
71 _, err := w.Write([]byte(tc.input))
72 if err != nil {
73 t.Errorf("%s: Unexpected error: %v", k, err)
74 }
75 result := b.String()
76 if !strings.Contains(result, "Iam") {
77 t.Errorf("%s: Expected to contain \"Iam\"", k)
78 }
79 if len(result) < len(tc.input) {
80 t.Errorf(
81 "%s: Unexpectedly short string, got %d wanted at least %d chars: %q",
82 k,
83 len(result),
84 len(tc.input),
85 result,
86 )
87 }
88 lines := strings.Split(result, "\n")
89 for i, line := range lines {
90 if len(line) > int(tc.maxWidth) {
91 t.Errorf("%s: Every line must be at most %d chars long, got %d: %q", k, tc.maxWidth, len(line), line)
92 }
93 if i < len(lines)-1 && len(line) != int(tc.maxWidth) {
94 t.Errorf(
95 "%s: Lines except the last one are expected to be exactly %d chars long, got %d: %q",
96 k,
97 tc.maxWidth,
98 len(line),
99 line,
100 )
101 }
102 }
103 }
104}

Callers

nothing calls this directly

Calls 4

NewMaxWidthWriterFunction · 0.85
WriteMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…