github.com/go-oss/image@v0.1.1-0.20230517025328-001b78555e78/imageutil/decode_test.go (about)

     1  package imageutil
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestDecode_JPEGQuality(t *testing.T) {
    12  	assert := assert.New(t)
    13  
    14  	testFiles := []string{
    15  		"../testdata/garden.jpg",
    16  		"../testdata/garden.png",
    17  	}
    18  
    19  	expectedQuality := []int{71, 0}
    20  
    21  	for i, fileName := range testFiles {
    22  		filePath, err := filepath.Abs(fileName)
    23  		assert.NoError(err)
    24  
    25  		file, err := os.Open(filePath)
    26  		assert.NoError(err)
    27  		defer file.Close()
    28  
    29  		img, err := Decode(file)
    30  		assert.NoError(err)
    31  
    32  		assert.Equal(expectedQuality[i], img.Quality, fileName)
    33  	}
    34  }