Skip to content

Commit

Permalink
[+] Add ReadFile to fixtures, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cthulhu committed Jan 10, 2018
1 parent 0c7cb45 commit 864fb07
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
8 changes: 5 additions & 3 deletions fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import (
)

func Read(filename string) []byte {
file, err := os.Open("fixtures/" + filename)
return ReadFile("fixtures/" + filename)
}

func ReadFile(path string) []byte {
file, err := os.Open(path)
if err != nil {
panic(err)
}

d, err := ioutil.ReadAll(file)
if err != nil {
panic(err)
}

return d
}
13 changes: 13 additions & 0 deletions fixture/fixture_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fixture_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestFixture(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Fixture Suite")
}
21 changes: 21 additions & 0 deletions fixture/fixture_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fixture_test

import (
. "github.com/cthulhu/go-steun/fixture"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Fixture", func() {
Context("Read", func() {
It("reads the fixture", func() {
Expect(string(Read("one.txt"))).To(BeEquivalentTo("expected\n"))
})
})
Context("ReadFile", func() {
It("reads the fixture", func() {
Expect(string(ReadFile("fixtures/one.txt"))).To(BeEquivalentTo("expected\n"))
})
})
})
1 change: 1 addition & 0 deletions fixture/fixtures/one.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expected

0 comments on commit 864fb07

Please sign in to comment.