Skip to content

Commit

Permalink
Check hash of each test render
Browse files Browse the repository at this point in the history
Add a function to hash the Processed image for testing
  • Loading branch information
LukeHandle committed Dec 30, 2014
1 parent 6eca931 commit ab2729c
Showing 1 changed file with 58 additions and 19 deletions.
77 changes: 58 additions & 19 deletions main_test.go
@@ -1,18 +1,36 @@
package main

import (
"crypto/md5"
"fmt"
"github.com/op/go-logging"
. "github.com/smartystreets/goconvey/convey"
"image"
_ "image/png"
"testing"
)

const (
testUser = "clone1018"
)

type SilentWriter struct {
}

func (w SilentWriter) Write(p []byte) (n int, err error) {
return 0, nil
}

func hashRender(render image.Image) string {
// md5 hash its pixels
hasher := md5.New()
hasher.Write(render.(*image.NRGBA).Pix)
md5Hash := fmt.Sprintf("%x", hasher.Sum(nil))

// And return the Hash
return md5Hash
}

func TestSetup(t *testing.T) {
logBackend := logging.NewLogBackend(SilentWriter{}, "", 0)
stats = MakeStatsCollector()
Expand All @@ -22,60 +40,81 @@ func TestSetup(t *testing.T) {
}

func TestRenders(t *testing.T) {
Convey("GetHead should return valid a image", t, func() {
skin := fetchSkin("clone1018")
Convey("GetHead should return a valid image", t, func() {
skin := fetchSkin(testUser)
err := skin.GetHead(20)

So(skin.Processed, ShouldNotBeNil)
So(err, ShouldBeNil)

hash := hashRender(skin.Processed)
So(hash, ShouldEqual, "257972f3af185ce1f92200156d3bfe97")
})

Convey("GetHelm should return valid a image", t, func() {
skin := fetchSkin("clone1018")
Convey("GetHelm should return a valid image", t, func() {
skin := fetchSkin(testUser)
err := skin.GetHelm(20)

So(skin.Processed, ShouldNotBeNil)
So(err, ShouldBeNil)

hash := hashRender(skin.Processed)
So(hash, ShouldEqual, "257972f3af185ce1f92200156d3bfe97")
})

Convey("GetCube should return valid a image", t, func() {
skin := fetchSkin("clone1018")
Convey("GetCube should return a valid image", t, func() {
skin := fetchSkin(testUser)
err := skin.GetCube(20)

So(skin.Processed, ShouldNotBeNil)
So(err, ShouldBeNil)

hash := hashRender(skin.Processed)
So(hash, ShouldEqual, "a579af057377c35cbd4e53ed6bc5f03e")
})

Convey("GetBust should return valid a image", t, func() {
skin := fetchSkin("clone1018")
Convey("GetBust should return a valid image", t, func() {
skin := fetchSkin(testUser)
err := skin.GetBust(20)

So(skin.Processed, ShouldNotBeNil)
So(err, ShouldBeNil)

hash := hashRender(skin.Processed)
So(hash, ShouldEqual, "1a4ba8567619350883923bde97626ae6")
})

Convey("GetBody should return valida image", t, func() {
skin := fetchSkin("clone1018")
Convey("GetBody should return a valid image", t, func() {
skin := fetchSkin(testUser)
err := skin.GetBody(20)

So(skin.Processed, ShouldNotBeNil)
So(err, ShouldBeNil)

hash := hashRender(skin.Processed)
So(hash, ShouldEqual, "987cc81d031386f429b12da2cd5c1ff2")
})

Convey("GetArmorBust should return a valid image", t, func() {
skin := fetchSkin("clone1018")
skin := fetchSkin(testUser)
err := skin.GetArmorBust(20)

So(skin.Processed, ShouldNotBeNil)
So(err, ShouldBeNil)

hash := hashRender(skin.Processed)
So(hash, ShouldEqual, "1a4ba8567619350883923bde97626ae6")
})

Convey("GetArmorBody should return a valid image", t, func() {
skin := fetchSkin("clone1018")
skin := fetchSkin(testUser)
err := skin.GetArmorBody(20)

So(skin.Processed, ShouldNotBeNil)
So(err, ShouldBeNil)

hash := hashRender(skin.Processed)
So(hash, ShouldEqual, "987cc81d031386f429b12da2cd5c1ff2")
})
}

Expand All @@ -88,7 +127,7 @@ func BenchmarkSetup(b *testing.B) {
}

func BenchmarkGetHead(b *testing.B) {
skin := fetchSkin("clone1018")
skin := fetchSkin(testUser)
b.ResetTimer()

for n := 0; n < b.N; n++ {
Expand All @@ -97,7 +136,7 @@ func BenchmarkGetHead(b *testing.B) {
}

func BenchmarkGetHelm(b *testing.B) {
skin := fetchSkin("clone1018")
skin := fetchSkin(testUser)
b.ResetTimer()

for n := 0; n < b.N; n++ {
Expand All @@ -106,7 +145,7 @@ func BenchmarkGetHelm(b *testing.B) {
}

func BenchmarkGetCube(b *testing.B) {
skin := fetchSkin("clone1018")
skin := fetchSkin(testUser)
b.ResetTimer()

for n := 0; n < b.N; n++ {
Expand All @@ -115,7 +154,7 @@ func BenchmarkGetCube(b *testing.B) {
}

func BenchmarkGetBust(b *testing.B) {
skin := fetchSkin("clone1018")
skin := fetchSkin(testUser)
b.ResetTimer()

for n := 0; n < b.N; n++ {
Expand All @@ -124,7 +163,7 @@ func BenchmarkGetBust(b *testing.B) {
}

func BenchmarkGetBody(b *testing.B) {
skin := fetchSkin("clone1018")
skin := fetchSkin(testUser)
b.ResetTimer()

for n := 0; n < b.N; n++ {
Expand All @@ -133,7 +172,7 @@ func BenchmarkGetBody(b *testing.B) {
}

func BenchmarkGetArmorBust(b *testing.B) {
skin := fetchSkin("clone1018")
skin := fetchSkin(testUser)
b.ResetTimer()

for n := 0; n < b.N; n++ {
Expand All @@ -142,7 +181,7 @@ func BenchmarkGetArmorBust(b *testing.B) {
}

func BenchmarkGetArmorBody(b *testing.B) {
skin := fetchSkin("clone1018")
skin := fetchSkin(testUser)
b.ResetTimer()

for n := 0; n < b.N; n++ {
Expand Down

0 comments on commit ab2729c

Please sign in to comment.