From a94dcb9918b5fec133faf5df65144d48e8722ca8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 23 Mar 2019 20:07:57 -0500 Subject: Do not save duplicate images Adding the same image should create a drawing referencing the already stored copy of the image. Closes #359 --- picture_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'picture_test.go') diff --git a/picture_test.go b/picture_test.go index 518713f..2b39ed8 100644 --- a/picture_test.go +++ b/picture_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -146,3 +147,20 @@ func TestAddDrawingPicture(t *testing.T) { f := NewFile() assert.EqualError(t, f.addDrawingPicture("sheet1", "", "A", "", 0, 0, 0, 0, nil), `cannot convert cell "A" to coordinates: invalid cell name "A"`) } + +func TestAddPictureFromBytes(t *testing.T) { + f := NewFile() + imgFile, err := ioutil.ReadFile("logo.png") + if err != nil { + t.Error("Unable to load logo for test") + } + f.AddPictureFromBytes("Sheet1", fmt.Sprint("A", 1), "", "logo", ".png", imgFile) + f.AddPictureFromBytes("Sheet1", fmt.Sprint("A", 50), "", "logo", ".png", imgFile) + imageCount := 0 + for fileName := range f.XLSX { + if strings.Contains(fileName, "media/image") { + imageCount++ + } + } + assert.Equal(t, 1, imageCount, "Duplicate image should only be stored once.") +} -- cgit v1.2.1