Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
net/http/httptest が推しです♡
Search
Kotaro Otaka
October 24, 2024
Programming
440
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
net/http/httptest が推しです♡
The Go gopher was designed by Renée French.
https://gotalk.connpass.com/event/331992/
Kotaro Otaka
October 24, 2024
More Decks by Kotaro Otaka
See All by Kotaro Otaka
actions/setup-go 完全に理解した
otakakot
1
43
Vendoring をやめたけどやめたのは正解だったのか
otakakot
0
65
t *testing.T は どこからやってくるの?
otakakot
1
1.1k
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
1.4k
Go で作った CLI ツールにバージョンを埋め込みたい
otakakot
0
250
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
640
組込みだけじゃない! TinyGo で始める無料クラウド開発入門
otakakot
1
180
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
1
3.9k
SQLBoiler がメンテナンスモードになりまして
otakakot
0
390
Other Decks in Programming
See All in Programming
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
5.6k
Intent as Code
shoppingjaws
4
670
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
150
LLMは4年分のCompose移行を再現できるのか?実プロダクト279件のXMLで探る自動化の境界線
makun
0
480
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.1k
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
Foundry Localでエージェント開発
seosoft
0
160
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
430
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
150
XHTMLが残したもの
yosuke_furukawa
PRO
2
610
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
6
3.3k
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
100
6.3k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
450
sira's awesome portfolio website redesign presentation
elsirapls
0
410
Evolving SEO for Evolving Search Engines
ryanjones
0
280
A Tale of Four Properties
chriscoyier
163
24k
Leo the Paperboy
mayatellez
9
2.3k
Google's AI Overviews - The New Search
badams
0
1.6k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
We Have a Design System, Now What?
morganepeng
55
8.3k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
300
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. いい距離感でテストと付き合っていこうね