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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kotaro Otaka
October 24, 2024
Programming
420
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
Vendoring をやめたけどやめたのは正解だったのか
otakakot
0
41
t *testing.T は どこからやってくるの?
otakakot
1
1k
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
1.2k
Go で作った CLI ツールにバージョンを埋め込みたい
otakakot
0
230
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
600
組込みだけじゃない! TinyGo で始める無料クラウド開発入門
otakakot
1
150
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
1
3.8k
SQLBoiler がメンテナンスモードになりまして
otakakot
0
360
Wasm わからないけど Go で実装したいから入門する
otakakot
1
11k
Other Decks in Programming
See All in Programming
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
630
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
460
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
230
スマートグラスで並列バイブコーディング
hyshu
0
270
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
780
The NotImplementedError Problem in Ruby
koic
1
1.1k
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.7k
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.9k
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
0
180
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
320
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
210
Featured
See All Featured
Evolving SEO for Evolving Search Engines
ryanjones
0
230
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
400
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
180
Un-Boring Meetings
codingconduct
0
330
Marketing to machines
jonoalderson
1
5.5k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
660
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
200
Color Theory Basics | Prateek | Gurzu
gurzu
0
380
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
240
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
250
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. いい距離感でテストと付き合っていこうね