Skip to content

Instantly share code, notes, and snippets.

@NetguruGist
Created November 28, 2016 13:36
Show Gist options
  • Save NetguruGist/5f51996bb2690bff1f10910e17b54d19 to your computer and use it in GitHub Desktop.
Save NetguruGist/5f51996bb2690bff1f10910e17b54d19 to your computer and use it in GitHub Desktop.
func (s *Scene) Save(filename string) {
f, err := os.Create(filename)
if err != nil {
panic(err)
}
defer f.Close()
png.Encode(f, s.Img)
}
func TestSceneSavePanicsWhenFileCannotBePersisted(t *testing.T) {
scene := NewScene(4, 4)
c := randomColor()
scene.EachPixel(func(x, y int) color.RGBA { return c })
assert.Panics(t, func() {
scene.Save("/etc/temp.png")
}, "panics when the file cannot be persisted")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment