Skip to content

Commit

Permalink
resource_test.go: Fixed for compat with earlier Go versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsoprea committed Jan 7, 2019
1 parent f65458c commit 00ae89f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This project was created in order to solve the problem of producing an HTML-base
- Website structure is serializable and therefore storable so that it can be stored, recalled, modified, and rerendered later.
- When the website is rendered, it is first rendered as intermediate content and then rendered as HTML content. This allows us to focus on producing lightweight markup while being able to offload the actual HTML production to a third-party tool that specializes in that. This consequently enables you to debug content issues in the HTML by inspecting the intermediate content.
- The intermediate content supports multiple dialects. This project comes with a [Markdown](https://daringfireball.net/projects/markdown) dialect.
- Images can be embedded directly into the HTML content.


# Example
Expand Down
27 changes: 18 additions & 9 deletions resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io/ioutil"
"os"
"path"
"testing"

"github.com/dsoprea/go-logging"
Expand Down Expand Up @@ -36,15 +37,25 @@ func TestNewEmbeddedResourceLocatorWithReader(t *testing.T) {
}
}

func TestNewEmbeddedResourceLocatorWithFilepath_DetectMimetype_Deferred(t *testing.T) {
f, err := ioutil.TempFile("", "resource*.png")
func getTempFilepath(filename string) (tempPath string, f *os.File) {
tempPath, err := ioutil.TempDir("", "")
log.PanicIf(err)

defer os.Remove(f.Name())
filepath := path.Join(tempPath, filename)

f, err = os.Create(filepath)
log.PanicIf(err)

return tempPath, f
}

func TestNewEmbeddedResourceLocatorWithFilepath_DetectMimetype_Deferred(t *testing.T) {
tempPath, f := getTempFilepath("resource.png")
defer os.RemoveAll(tempPath)

raw := []byte{1, 2, 3}

_, err = f.Write(raw)
_, err := f.Write(raw)
log.PanicIf(err)

err = f.Sync()
Expand Down Expand Up @@ -101,14 +112,12 @@ func TestNewEmbeddedResourceLocatorWithFilepath_NoDetectMimetype_Deferred(t *tes
}

func TestNewEmbeddedResourceLocatorWithFilepath_DetectMimetype_NoDefer(t *testing.T) {
f, err := ioutil.TempFile("", "resource*.png")
log.PanicIf(err)

defer os.Remove(f.Name())
tempPath, f := getTempFilepath("resource.png")
defer os.RemoveAll(tempPath)

raw := []byte{1, 2, 3}

_, err = f.Write(raw)
_, err := f.Write(raw)
log.PanicIf(err)

err = f.Sync()
Expand Down

0 comments on commit 00ae89f

Please sign in to comment.