forked from trumail/trumail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement tests for HasGravatar function
- Loading branch information
Helielson
authored and
Steven Wolfe
committed
Oct 24, 2017
1 parent
8d2d357
commit abc202d
Showing
4 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
NOVENDOR_PATH = $$(glide novendor) | ||
|
||
runtest: | ||
go clean | ||
go test ${NOVENDOR_PATH} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package verifier | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"testing" | ||
|
||
"gopkg.in/check.v1" | ||
"gopkg.in/h2non/gock.v1" | ||
) | ||
|
||
type gravatarSuite struct{} | ||
|
||
var _ = check.Suite(&gravatarSuite{}) | ||
|
||
func Test(t *testing.T) { check.TestingT(t) } // Just to make discoverable | ||
|
||
func configureRequestMock(addressMD5 string, statusCode int) *gock.Response { | ||
url := "https://en.gravatar.com/" + addressMD5 + ".json" | ||
return gock.New(url). | ||
Head(""). | ||
Reply(statusCode) | ||
} | ||
|
||
func (s *gravatarSuite) TestHasGravatarStatusOk(c *check.C) { | ||
address := &Address{ | ||
Username: "username", | ||
Domain: "domain.com", | ||
Address: "[email protected]", | ||
} | ||
|
||
configureRequestMock(address.MD5(), http.StatusOK) | ||
defer gock.Off() | ||
|
||
c.Assert(HasGravatar(address), check.Equals, true) | ||
} | ||
|
||
func (s *gravatarSuite) TestHasGravatarRequestError(c *check.C) { | ||
address := &Address{ | ||
Username: "username", | ||
Domain: "domain.com", | ||
Address: "[email protected]", | ||
} | ||
|
||
gockResponse := configureRequestMock(address.MD5(), 200) | ||
gockResponse.SetError(errors.New("Some error while requesting")) | ||
defer gock.Off() | ||
|
||
c.Assert(HasGravatar(address), check.Equals, false) | ||
} | ||
|
||
func (s *gravatarSuite) TestHasGravatarStatusNotOk(c *check.C) { | ||
address := &Address{ | ||
Username: "username", | ||
Domain: "domain.com", | ||
Address: "[email protected]", | ||
} | ||
|
||
configureRequestMock(address.MD5(), http.StatusBadRequest) | ||
defer gock.Off() | ||
|
||
c.Assert(HasGravatar(address), check.Equals, false) | ||
} |