Skip to content

Commit 50301c4

Browse files
committed
Fix type assertion checks in tests
1 parent 6a916ba commit 50301c4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

image_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,13 @@ func (testNamedReader) Name() string { return "named.txt" }
165165
func TestWrapReader(t *testing.T) {
166166
r := bytes.NewBufferString("data")
167167
wrapped := WrapReader(r, "file.png", "image/png")
168-
f := wrapped.(interface {
168+
f, ok := wrapped.(interface {
169169
Name() string
170170
ContentType() string
171171
})
172+
if !ok {
173+
t.Fatal("wrapped reader missing Name or ContentType")
174+
}
172175
if f.Name() != "file.png" {
173176
t.Fatalf("expected name file.png, got %s", f.Name())
174177
}
@@ -179,10 +182,13 @@ func TestWrapReader(t *testing.T) {
179182
// test name from underlying reader
180183
nr := testNamedReader{Reader: bytes.NewBufferString("d")}
181184
wrapped = WrapReader(nr, "", "text/plain")
182-
f = wrapped.(interface {
185+
f, ok = wrapped.(interface {
183186
Name() string
184187
ContentType() string
185188
})
189+
if !ok {
190+
t.Fatal("wrapped named reader missing Name or ContentType")
191+
}
186192
if f.Name() != "named.txt" {
187193
t.Fatalf("expected name named.txt, got %s", f.Name())
188194
}
@@ -192,7 +198,10 @@ func TestWrapReader(t *testing.T) {
192198

193199
// no name provided
194200
wrapped = WrapReader(bytes.NewBuffer(nil), "", "")
195-
f2 := wrapped.(interface{ Name() string })
201+
f2, ok := wrapped.(interface{ Name() string })
202+
if !ok {
203+
t.Fatal("wrapped anonymous reader missing Name")
204+
}
196205
if f2.Name() != "" {
197206
t.Fatalf("expected empty name, got %s", f2.Name())
198207
}

0 commit comments

Comments
 (0)