forked from mainephd/sonago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sonago_test.go
80 lines (76 loc) · 2.42 KB
/
sonago_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
77
78
79
80
package main
import (
"encoding/xml"
"flag"
"io/ioutil"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Sonago", func() {
var expectedCoverageOutput []byte
var expectedFileName string
var expectedCoverageStruct coverage
BeforeEach(func() {
expectedFileName = "coverage.xml"
expectedCoverageOutput, _ = ioutil.ReadFile(expectedFileName)
xml.Unmarshal(expectedCoverageOutput, expectedCoverageStruct)
})
Describe("when outputfile is specified it", func() {
It("should write to the file specified", func() {
outputFilename := "testspecifiedfile.xml"
flag.Set("outputfile", outputFilename)
main()
file, err := ioutil.ReadFile(outputFilename)
Expect(err).ToNot(HaveOccurred())
var actualCoverageStruct coverage
xml.Unmarshal(file, actualCoverageStruct)
Expect(actualCoverageStruct).To(Equal(expectedCoverageStruct))
})
})
Describe("when inputfile is specified", func() {
It("should read to the file specified", func() {
filename := "test.coverprofile"
flag.Set("inputfile", filename)
main()
file, err := ioutil.ReadFile(expectedFileName)
Expect(err).ToNot(HaveOccurred())
var actualCoverageStruct coverage
xml.Unmarshal(file, actualCoverageStruct)
Expect(actualCoverageStruct).To(Equal(expectedCoverageStruct))
})
})
Describe("when outputfile is not specified", func() {
It("should write contents to coverage.xml", func() {
main()
file, err := ioutil.ReadFile(expectedFileName)
Expect(err).ToNot(HaveOccurred())
var actualCoverageStruct coverage
xml.Unmarshal(file, actualCoverageStruct)
Expect(actualCoverageStruct).To(Equal(expectedCoverageStruct))
})
})
Describe("when inputfile is not specified", func() {
It("should read contents from gover.coverprofile", func() {
main()
file, err := ioutil.ReadFile(expectedFileName)
Expect(err).ToNot(HaveOccurred())
var actualCoverageStruct coverage
xml.Unmarshal(file, actualCoverageStruct)
Expect(actualCoverageStruct).To(Equal(expectedCoverageStruct))
})
})
Describe("When errors", func() {
Describe("occur opening inputfile it", func() {
It("cause the utility to panic", func() {
flag.Set("inputfile", "iamnotpresent.coverprofile")
Expect(main).To(Panic())
})
})
Describe("occur parsing coverprofile it", func() {
It("cause the utility to panic", func() {
flag.Set("inputfile", "bad-gover.coverprofile")
Expect(main).To(Panic())
})
})
})
})