@@ -258,14 +258,6 @@ func TestCameraWithProjector(t *testing.T) {
258258 test .That (t , cam2 .Close (context .Background ()), test .ShouldBeNil )
259259}
260260
261- // verifyImageEquality compares two images and verifies they are identical.
262- func verifyImageEquality (t * testing.T , img1 , img2 image.Image ) {
263- t .Helper ()
264- diff , _ , err := rimage .CompareImages (img1 , img2 )
265- test .That (t , err , test .ShouldBeNil )
266- test .That (t , diff , test .ShouldEqual , 0 )
267- }
268-
269261// verifyDecodedImage verifies that decoded image bytes match the original image.
270262func verifyDecodedImage (t * testing.T , imgBytes []byte , mimeType string , originalImg image.Image ) {
271263 t .Helper ()
@@ -283,7 +275,7 @@ func verifyDecodedImage(t *testing.T, imgBytes []byte, mimeType string, original
283275 // For other formats, compare the decoded images
284276 decodedImg , err := rimage .DecodeImage (context .Background (), imgBytes , mimeType )
285277 test .That (t , err , test .ShouldBeNil )
286- verifyImageEquality (t , decodedImg , originalImg )
278+ test . That (t , rimage . ImagesExactlyEqual ( decodedImg , originalImg ), test . ShouldBeTrue )
287279}
288280
289281func TestGetImageFromGetImages (t * testing.T ) {
@@ -409,7 +401,7 @@ func TestGetImagesFromGetImage(t *testing.T) {
409401 test .That (t , images [0 ].SourceName , test .ShouldEqual , "" )
410402 img , err := images [0 ].Image (context .Background ())
411403 test .That (t , err , test .ShouldBeNil )
412- verifyImageEquality (t , img , testImg )
404+ test . That (t , rimage . ImagesExactlyEqual ( img , testImg ), test . ShouldBeTrue )
413405 test .That (t , metadata .CapturedAt .IsZero (), test .ShouldBeFalse )
414406 test .That (t , metadata .CapturedAt .After (startTime ), test .ShouldBeTrue )
415407 test .That (t , metadata .CapturedAt .Before (endTime ), test .ShouldBeTrue )
@@ -453,7 +445,7 @@ func TestGetImagesFromGetImage(t *testing.T) {
453445 test .That (t , metadata .CapturedAt .Before (endTime ), test .ShouldBeTrue )
454446 img , err := images [0 ].Image (context .Background ())
455447 test .That (t , err , test .ShouldBeNil )
456- verifyImageEquality (t , img , rgbaImg ) // we should ignore the requested mime type and get back an RGBA image
448+ test . That (t , rimage . ImagesExactlyEqual ( img , rgbaImg ), test . ShouldBeTrue )
457449 })
458450
459451 t .Run ("error case" , func (t * testing.T ) {
@@ -503,7 +495,7 @@ func TestImages(t *testing.T) {
503495 test .That (t , len (images ), test .ShouldEqual , 1 )
504496 img , err := images [0 ].Image (ctx )
505497 test .That (t , err , test .ShouldBeNil )
506- verifyImageEquality (t , img , respImg )
498+ test . That (t , rimage . ImagesExactlyEqual ( img , respImg ), test . ShouldBeTrue )
507499 test .That (t , images [0 ].SourceName , test .ShouldEqual , source1Name )
508500 })
509501
@@ -592,7 +584,7 @@ func TestImages(t *testing.T) {
592584 test .That (t , imgs [0 ].MimeType (), test .ShouldEqual , rutils .MimeTypeRawDepth )
593585 img , err := imgs [0 ].Image (ctx )
594586 test .That (t , err , test .ShouldBeNil )
595- verifyImageEquality (t , img , img2 )
587+ test . That (t , rimage . ImagesExactlyEqual ( img , img2 ), test . ShouldBeTrue )
596588 })
597589
598590 t .Run ("multiple valid sources" , func (t * testing.T ) {
@@ -609,12 +601,12 @@ func TestImages(t *testing.T) {
609601 test .That (t , imgs [0 ].MimeType (), test .ShouldEqual , rutils .MimeTypeJPEG )
610602 img , err := imgs [0 ].Image (ctx )
611603 test .That (t , err , test .ShouldBeNil )
612- verifyImageEquality (t , img , img3 )
604+ test . That (t , rimage . ImagesExactlyEqual ( img , img3 ), test . ShouldBeTrue )
613605
614606 test .That (t , imgs [1 ].MimeType (), test .ShouldEqual , rutils .MimeTypePNG )
615607 img , err = imgs [1 ].Image (ctx )
616608 test .That (t , err , test .ShouldBeNil )
617- verifyImageEquality (t , img , img1 )
609+ test . That (t , rimage . ImagesExactlyEqual ( img , img1 ), test . ShouldBeTrue )
618610 })
619611
620612 t .Run ("single invalid source" , func (t * testing.T ) {
@@ -641,7 +633,7 @@ func TestNamedImage(t *testing.T) {
641633 badBytes := []byte ("trust bro i'm an image ong" )
642634 sourceName := "test_source"
643635
644- t .Run ("NamedImageFromBytes" , func (t * testing.T ) {
636+ t .Run ("NamedImageFromBytes" , func (t * testing.T ) {
645637 t .Run ("success" , func (t * testing.T ) {
646638 ni , err := camera .NamedImageFromBytes (testImgPNGBytes , sourceName , rutils .MimeTypePNG )
647639 test .That (t , err , test .ShouldBeNil )
@@ -658,15 +650,15 @@ func TestNamedImage(t *testing.T) {
658650 })
659651 })
660652
661- t .Run ("NamedImageFromImage" , func (t * testing.T ) {
653+ t .Run ("NamedImageFromImage" , func (t * testing.T ) {
662654 t .Run ("success" , func (t * testing.T ) {
663655 ni , err := camera .NamedImageFromImage (testImg , sourceName , rutils .MimeTypePNG )
664656 test .That (t , err , test .ShouldBeNil )
665657 test .That (t , ni .SourceName , test .ShouldEqual , sourceName )
666658 test .That (t , ni .MimeType (), test .ShouldEqual , rutils .MimeTypePNG )
667659 img , err := ni .Image (ctx )
668660 test .That (t , err , test .ShouldBeNil )
669- verifyImageEquality (t , img , testImg )
661+ test . That (t , rimage . ImagesExactlyEqual ( img , testImg ), test . ShouldBeTrue )
670662 })
671663 t .Run ("error on nil image" , func (t * testing.T ) {
672664 _ , err := camera .NamedImageFromImage (nil , sourceName , rutils .MimeTypePNG )
@@ -684,7 +676,7 @@ func TestNamedImage(t *testing.T) {
684676 test .That (t , err , test .ShouldBeNil )
685677 img , err := ni .Image (ctx )
686678 test .That (t , err , test .ShouldBeNil )
687- verifyImageEquality (t , img , testImg )
679+ test . That (t , rimage . ImagesExactlyEqual ( img , testImg ), test . ShouldBeTrue )
688680
689681 // should return the same image instance
690682 img2 , err := ni .Image (ctx )
@@ -699,12 +691,12 @@ func TestNamedImage(t *testing.T) {
699691 // first call should decode
700692 img , err := ni .Image (ctx )
701693 test .That (t , err , test .ShouldBeNil )
702- verifyImageEquality (t , img , testImg )
694+ test . That (t , rimage . ImagesExactlyEqual ( img , testImg ), test . ShouldBeTrue )
703695
704696 // second call should return cached image
705697 img2 , err := ni .Image (ctx )
706698 test .That (t , err , test .ShouldBeNil )
707- verifyImageEquality (t , img2 , testImg )
699+ test . That (t , rimage . ImagesExactlyEqual ( img2 , testImg ), test . ShouldBeTrue )
708700 test .That (t , reflect .ValueOf (img ).Pointer (), test .ShouldEqual , reflect .ValueOf (img2 ).Pointer ())
709701 })
710702
0 commit comments