This repository has been archived by the owner on May 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
integration_test.go
76 lines (58 loc) · 1.75 KB
/
integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main_test
import (
"crypto/sha256"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
"io"
"io/ioutil"
"os"
"os/exec"
"path"
"runtime"
)
var _ = Describe("Remove.bg CLI: zip2png command", func() {
var (
exampleZip string
referencePath string
outputPath string
testDir string
tmpOutputDir string
)
BeforeEach(func() {
_, testFile, _, _ := runtime.Caller(0)
testDir = path.Dir(testFile)
exampleZip = path.Join(testDir, "fixtures/zip/example-cat.zip")
Expect(exampleZip).To(BeAnExistingFile())
referencePath = path.Join(testDir, "fixtures/zip/reference-example-cat.png")
Expect(referencePath).To(BeAnExistingFile())
tmpOutputDir, _ = ioutil.TempDir("", "removeBG-*")
outputPath = path.Join(tmpOutputDir, "cat-composite.png")
})
AfterEach(func() {
os.RemoveAll(tmpOutputDir)
})
It("combines the color.jpg and alpha.png into a transparent PNG", func() {
command := exec.Command(cliPath, "zip2png", exampleZip, outputPath)
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
Eventually(session, 30).Should(gexec.Exit())
Expect(session.ExitCode()).To(Equal(0))
Expect(session.Err).To(gbytes.Say("Processed zip"))
Expect(outputPath).To(BeAnExistingFile())
outputSha := fileSha(outputPath)
referenceSha := fileSha(referencePath)
Expect(outputSha).To(Equal(referenceSha), "Expected output composite to match reference composite")
})
})
func fileSha(filepath string) []byte {
Expect(filepath).To(BeAnExistingFile())
f, err := os.Open(filepath)
Expect(err).To(BeNil())
defer f.Close()
h := sha256.New()
_, err = io.Copy(h, f)
Expect(err).To(BeNil())
return h.Sum(nil)
}