Last active
April 29, 2019 19:49
-
-
Save KamilLelonek/89ed68d3102aa504e5b00e533963714a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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