MCPcopy Create free account
hub / github.com/Shopify/goose / TestBasicOperations

Function TestBasicOperations

syncio/buffer_test.go:119–180  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestBasicOperations(t *testing.T) {
120 var buf Buffer
121
122 for i := 0; i < 5; i++ {
123 check(t, "TestBasicOperations (1)", &buf, "")
124
125 buf.Reset()
126 check(t, "TestBasicOperations (2)", &buf, "")
127
128 buf.Truncate(0)
129 check(t, "TestBasicOperations (3)", &buf, "")
130
131 n, err := buf.Write(testBytes[0:1])
132 if n != 1 {
133 t.Errorf("wrote 1 byte, but n == %d", n)
134 }
135 if err != nil {
136 t.Errorf("err should always be nil, but err == %s", err)
137 }
138 check(t, "TestBasicOperations (4)", &buf, "a")
139
140 err = buf.WriteByte(testString[1])
141 if err != nil {
142 t.Error("WriteByte unexpected err")
143 }
144 check(t, "TestBasicOperations (5)", &buf, "ab")
145
146 n, err = buf.Write(testBytes[2:26])
147 if err != nil {
148 t.Error("Write unexpected err")
149 }
150 if n != 24 {
151 t.Errorf("wrote 24 bytes, but n == %d", n)
152 }
153 check(t, "TestBasicOperations (6)", &buf, testString[0:26])
154
155 buf.Truncate(26)
156 check(t, "TestBasicOperations (7)", &buf, testString[0:26])
157
158 buf.Truncate(20)
159 check(t, "TestBasicOperations (8)", &buf, testString[0:20])
160
161 empty(t, "TestBasicOperations (9)", &buf, testString[0:20], make([]byte, 5))
162 empty(t, "TestBasicOperations (10)", &buf, "", make([]byte, 100))
163
164 err = buf.WriteByte(testString[1])
165 if err != nil {
166 t.Error("WriteByte unexpected err")
167 }
168 c, err := buf.ReadByte()
169 if err != nil {
170 t.Error("ReadByte unexpected eof")
171 }
172 if c != testString[1] {
173 t.Errorf("ReadByte wrong value c=%v", c)
174 }
175 _, err = buf.ReadByte()
176 if err == nil {

Callers

nothing calls this directly

Calls 8

ResetMethod · 0.95
TruncateMethod · 0.95
WriteMethod · 0.95
WriteByteMethod · 0.95
ReadByteMethod · 0.95
checkFunction · 0.85
emptyFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected