You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
ããã«ã¡ããã¯ã«ã«ã®ã¢ããã³ãã«ã¬ã³ãã¼2æ¥ç®ãæ å½ããå ã§ãã æè¿ã¯Goã°ããæ¸ãã¦ããã®ã§ãGoãã¿ã§ãã å¤é¨ã¸ã® http ã¢ã¯ã»ã¹ãããæã«æ§é ãç解ãã¦ããã¨ä¾¿å©ãªãhttp.RoundTripper ã«ã¤ãã¦æ¸ãã¾ãã http.RoundTripper ã¨ã¯ Go ã§ãå¤é¨ã«httpã¢ã¯ã»ã¹ããã¨ãã«ã¯ã net/http ããã±ã¼ã¸ã«ããã http.Client ã使ãã¾ãã ã¾ãããããããªAPIã®ã¯ã©ã¤ã¢ã³ãã©ã¤ãã©ãªã®ä¸ã§ãæ®ã©ã®å ´å http.Client ã使ããã¦ãã¦ãå®ç¾©ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ãã(ä¸é¨ã³ã¡ã³ãçç¥) type Client struct { // Transport specifies the mechanism by which individual // HTTP requests are made. // If nil, Def
I've investegated a way to mock HTTP request and response when writing a code to access to a HTTP API with http.Client. Finally, I found that I can do it by just implementing RoundTrip method of http.RoundTripper. Here is an example of mocking and proxying HTTP request and response. Running with go run main.go -mock mock, you can get mocked result and with go run main.go -mock proxy, you can get p
Goâs strong type system includes a concept called interface. In Go, an interface is a collection of function signatures. Any type that implements all of those functions is implicitly able to be used as an interface type. For example, Goâs empty interface, interface{}, is similar to Rubyâs BasicObject or Javaâs Object, from which all classes inherit in these languages. More concretely, Rubyâs Compa
ãã®è¨äºã¯æ ªå¼ä¼ç¤¾ãã¯ã¹ã(Lifull) Advent Calendar 2016ã®2æ¥ç®ã®è¨äºã§ãã ã¿ãªããã¯ããã¾ãã¦ããã¯ã¹ãã®chissoã§ãã ã¯ããã¦Qiitaã«æ稿ããã®ã§ãããããã¦ãã¾ãã ãããªãã¨ã¯ãã¦ããããã®è¨äºã§ã¯ãGolangã§èªåãã¹ãããããã³ã¼ããæ¸ãæ¹æ³ã«ã¤ãã¦ãç§ãªãã«æ°ã¥ãããã¨ãã¾ã¨ãã¾ãã æ³å®èªè æ®æ®µããRSpecãæ¸ãã¦ãã Golangåå¿è Interfaceã£ã¦ãªã«ï¼ ç®æãã¨ãã ãã¡ã½ããåä½ã§ãã¹ãã³ã¼ããå®è¡ã§ããç¶æ ã«ããã ããã ãã§ãã ç§ã¯æ®æ®µRubyãæ¸ããã¨ãå¤ããRSpecã使ã£ã¦ã¡ã½ããåä½ã§ã¦ããããã¹ããä½æãã¦ãã¾ãã ã§ãããRubyã¨åãæè¦ã§ã³ã¼ããæ¸ãã¦ãRSpecã¨åãããªã§Golangã®ãã¹ããæ¸ããã¨ãã¦ãããã¾ããã ï¼éçåä»ãã®è¨èªã»Interfaceã«çããããããã³ã¼ãããã¡
class TwitterClient { public function tweet($message) { return true; } } $hoge = new TwitterClient(); $hoge->tweet('大å¿ãªã'); // trueãè¿ã class ClientContainerTest extends PHPUnit_Framework_TestCase { public function test_ã¢ãã¯ãæ¸ãã¦ã¿ã() { $hoge = $this->getMock('TwitterClient', array('tweet')); $hoge->expects($this->any()) ->method('tweet') ->will($this->returnValue(true)); $hoge->tweet('大å¿ãªã'); // true
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}