Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
net/http/httptest が推しです♡
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Kotaro Otaka
October 24, 2024
Programming
3
380
net/http/httptest が推しです♡
The Go gopher was designed by Renée French.
https://gotalk.connpass.com/event/331992/
Kotaro Otaka
October 24, 2024
Tweet
Share
More Decks by Kotaro Otaka
See All by Kotaro Otaka
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
570
Go で作った CLI ツールにバージョンを埋め込みたい
otakakot
0
190
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
520
組込みだけじゃない! TinyGo で始める無料クラウド開発入門
otakakot
1
110
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
1
3.7k
SQLBoiler がメンテナンスモードになりまして
otakakot
0
310
Wasm わからないけど Go で実装したいから入門する
otakakot
1
10k
cmp.Or に感動した
otakakot
3
1k
無料で楽しむ Go サーバー開発のススメ
otakakot
11
4.1k
Other Decks in Programming
See All in Programming
米国のサイバーセキュリティタイムラインと見る Goの暗号パッケージの進化
tomtwinkle
2
610
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
660
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
210
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
2.5k
Fundamentals of Software Engineering In the Age of AI
therealdanvega
2
260
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
220
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
420
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
300
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
570
Go 1.26でのsliceのメモリアロケーション最適化 / Go 1.26 リリースパーティ #go126party
mazrean
1
420
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
170
AIコードレビューの導入・運用と AI駆動開発における「AI4QA」の取り組みについて
hagevvashi
0
500
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
40k
Facilitating Awesome Meetings
lara
57
6.8k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
Un-Boring Meetings
codingconduct
0
230
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
230
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Being A Developer After 40
akosma
91
590k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
640
Building Adaptive Systems
keathley
44
3k
So, you think you're a good person
axbom
PRO
2
2k
Paper Plane
katiecoart
PRO
0
48k
Transcript
おーたかこーたろー @otakakot The Go gopher was designed by Renée French.
net/http/httptest が推しです♡ 2024.10.23 Go Connect #3
The Go gopher was designed by Renée French. みなさんテストはお好きですか?
The Go gopher was designed by Renée French. 私はテストが好きです。
The Go gopher was designed by Renée French. でもテストコードの保守は嫌いです。
The Go gopher was designed by Renée French. だからなるべく書きたくない。
The Go gopher was designed by Renée French. そんな私がたどり着いた(と思っている) net/http/httptest
をご紹介
The Go gopher was designed by Renée French. Kotaro Otaka
おーたかこーたろー Web Engineer 新卒入社 Hello Golang! Web Engineer 株式会社ビットキー 2020.04 2021.04 2022.11 @otakakot
The Go gopher was designed by Renée French. アジェンダ 01.
net/http/httptest との出会い 02. net/http/httptest 03. net/http/httptest (私)の使い方
The Go gopher was designed by Renée French. アジェンダ 01.
net/http/httptest との出会い 02. net/http/httptest 03. net/http/httptest (私)の使い方
The Go gopher was designed by Renée French. net/http/httptest との出会い
• zitadel/oidc にコントリビュートしたとき • 統合テストで利用 PR: https://github.com/zitadel/oidc/pull/579 Zennの記事: OSSコントリビュートの実績を解除した
The Go gopher was designed by Renée French. アジェンダ 01.
net/http/httptest との出会い 02. net/http/httptest 03. net/http/httptest (私)の使い方
The Go gopher was designed by Renée French. net/http/httptest
The Go gopher was designed by Renée French. net/http/httptest •
NewRequest / ( NewRequestWithContext 1.23 で追加 ) ◦ リクエストを生成 ◦ http.NewRequest と違い戻り値に error がない • NewRecoder() ◦ サーバーのレスポンスを記録 • NewServer() ◦ 空いているポート番号を自動で選択してサーバーを起動
The Go gopher was designed by Renée French. アジェンダ 01.
net/http/httptest との出会い 02. net/http/httptest 03. net/http/httptest (私)の使い方
The Go gopher was designed by Renée French. net/http/httptest (私)の使い方
1. NewRequest + NewRecoder を利用 ➔ 特定の Handler を対象にテスト 2. NewServer を利用 ➔ Client を用いて実際に打鍵しテスト
The Go gopher was designed by Renée French. テスト対象の API
入力 ${name} 出力 Hello, ${name}
The Go gopher was designed by Renée French. NewRequest +
NewRecoder リクエストとレスポンスを作成 Hander の実行 レスポンスの検証 これだとうまく動かない場合がある ※ ※ Zennの記事: httptest.NewRequset で Go 1.22 で追加された PathValue の値を取得する にて解説
The Go gopher was designed by Renée French. テスト対象の Handler
を登録 httptest によりサーバー起動 後片付け NewServer 準備
The Go gopher was designed by Renée French. NewServer ※
スライドの都合でエラーハンドリングは省略 リクエストを作成 クライアントによる打鍵 レスポンスの検証 ※ httptest でリクエストを作ると Client.Do() はエラーとなる
The Go gopher was designed by Renée French. いい距離感でテストと付き合っていこうね