Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Last active April 29, 2019 19:49
Show Gist options
  • Save KamilLelonek/89ed68d3102aa504e5b00e533963714a to your computer and use it in GitHub Desktop.
Save KamilLelonek/89ed68d3102aa504e5b00e533963714a to your computer and use it in GitHub Desktop.
func gravatarHash(email string) []byte {
return md5.Sum([]byte(email))[:]
}
func gravatarURL(hash [16]byte, size uint32) string {
return fmt.Sprintf("https://www.gravatar.com/avatar/%x?s=%d", hash, size)
}
func gravatar(email string, size uint32) string {
hash := gravatarHash(email)
return gravatarURL(hash, size)
}
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestGravatar(t *testing.T) {
var size uint32 = 10
endpoint := "https://www.gravatar.com/avatar/cf38500a2cd3b6a2c8c1d4d8259e83f8?s=%v"
email := "[email protected]"
url := gravatar(email, size)
expected := fmt.Sprintf(endpoint, size)
assert.Equal(t, url, expected, "URLs are not the same.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment