From ab2729c077caaa0d69fb4d9c088a88ec4fbdeed2 Mon Sep 17 00:00:00 2001 From: LukeHandle Date: Tue, 30 Dec 2014 21:27:25 +0000 Subject: [PATCH] Check hash of each test render Add a function to hash the Processed image for testing --- main_test.go | 77 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/main_test.go b/main_test.go index a4f171a..986eccf 100644 --- a/main_test.go +++ b/main_test.go @@ -1,11 +1,19 @@ 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 { } @@ -13,6 +21,16 @@ 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() @@ -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") }) } @@ -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++ { @@ -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++ { @@ -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++ { @@ -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++ { @@ -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++ { @@ -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++ { @@ -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++ {