Skip to content

Commit 00ce2e5

Browse files
authored
テストコードでearly returnパターンを使用してifのネストを減らす (#272)
1 parent cd0e421 commit 00ce2e5

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

lib/amesh/amesh_test.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,15 @@ func TestCreateAmeshImage(t *testing.T) {
272272
return
273273
}
274274

275-
if tt.checkCenterColor {
276-
centerColor := result.RGBAAt(bounds.Dx()/2, bounds.Dy()/2)
277-
if centerColor.R != 255 || centerColor.G != 255 || centerColor.B != 255 || centerColor.A != 255 {
278-
t.Errorf("Expected white center pixel but got R=%d, G=%d, B=%d, A=%d",
279-
centerColor.R, centerColor.G, centerColor.B, centerColor.A)
280-
}
275+
if !tt.checkCenterColor {
276+
return
277+
}
278+
279+
centerColor := result.RGBAAt(bounds.Dx()/2, bounds.Dy()/2)
280+
281+
if centerColor.R != 255 || centerColor.G != 255 || centerColor.B != 255 || centerColor.A != 255 {
282+
t.Errorf("Expected white center pixel but got R=%d, G=%d, B=%d, A=%d",
283+
centerColor.R, centerColor.G, centerColor.B, centerColor.A)
281284
}
282285
})
283286
}
@@ -363,23 +366,25 @@ func TestCreateImageReaderWithClient(t *testing.T) {
363366
return
364367
}
365368

366-
if tt.expectError == nil {
367-
if result == nil {
368-
t.Error("CreateImageReaderWithClient() returned nil reader")
369-
return
370-
}
369+
if tt.expectError != nil {
370+
return
371+
}
371372

372-
// io.Readerからデータを読み取って、有効なPNGデータかチェック
373-
data, err := io.ReadAll(result)
374-
if err != nil {
375-
t.Error(err)
376-
return
377-
}
373+
if result == nil {
374+
t.Error("CreateImageReaderWithClient() returned nil reader")
375+
return
376+
}
378377

379-
// PNGデータのデコードを試行
380-
if _, _, err = image.Decode(bytes.NewReader(data)); err != nil {
381-
t.Error(err)
382-
}
378+
// io.Readerからデータを読み取って、有効なPNGデータかチェック
379+
data, err := io.ReadAll(result)
380+
if err != nil {
381+
t.Error(err)
382+
return
383+
}
384+
385+
// PNGデータのデコードを試行
386+
if _, _, err = image.Decode(bytes.NewReader(data)); err != nil {
387+
t.Error(err)
383388
}
384389
})
385390
}

0 commit comments

Comments
 (0)