タグ

関連タグで絞り込む (3)

タグの絞り込みを解除

mockとgolangに関するBigFatCatのブックマーク (4)

  • Go http.RoundTripper 実装ガイド - Qiita

    こんにちわ、ワカルのアドベントカレンダー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

    Go http.RoundTripper 実装ガイド - Qiita
    BigFatCat
    BigFatCat 2018/03/08
    http.RoundTripper
  • Mocking a HTTP access with http.Transport in Golang - oinume journal

    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

    Mocking a HTTP access with http.Transport in Golang - oinume journal
    BigFatCat
    BigFatCat 2018/03/08
    http.RoundTripper
  • Interface With Your Database in Go Tests

    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

    Interface With Your Database in Go Tests
    BigFatCat
    BigFatCat 2018/02/06
    DataAccessLayer ← DBなど。Collaborator ← DBを利用するstructなど。例: 引数としてJSONを受け取り、DBに書き込む場合などに使える。
  • Golangでテストしやすいコードをかく - Qiita

    この記事は株式会社ネクスト(Lifull) Advent Calendar 2016の2日目の記事です。 みなさんはじめまして、ネクストのchissoです。 はじめてQiitaに投稿するのでドキドキしています。 そんなことはさておき、この記事では、Golangで自動テストしやすいコードを書く方法について、私なりに気づいたことをまとめます。 想定読者 普段よくRSpecを書いている Golang初心者 Interfaceってなに? 目指すところ 「メソッド単位でテストコードを実行できる状態にする」 これだけです。 私は普段Rubyを書くことが多く、RSpecを使ってメソッド単位でユニットテストを作成しています。 ですが、Rubyと同じ感覚でコードを書いて、RSpecと同じノリでGolangのテストを書こうとしてハマりました。 (静的型付けの言語・Interfaceに疎く、そもそもコードがダメ

    Golangでテストしやすいコードをかく - Qiita
  • 1