summaryrefslogtreecommitdiff
path: root/picture_test.go
diff options
context:
space:
mode:
authorMichael <osiris2918@gmail.com>2019-03-23 20:07:57 -0500
committerHarris <mike.harris@cerner.com>2019-03-25 13:17:53 -0500
commita94dcb9918b5fec133faf5df65144d48e8722ca8 (patch)
tree7d691000cc2833989d8f5d37c201732b6b82f0f0 /picture_test.go
parentf0244c00161ad6372ceb1ec951f3a82c741cd46a (diff)
Do not save duplicate images
Adding the same image should create a drawing referencing the already stored copy of the image. Closes #359
Diffstat (limited to 'picture_test.go')
-rw-r--r--picture_test.go18
1 files changed, 18 insertions, 0 deletions
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.")
+}