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
400
3
Share
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
t *testing.T は どこからやってくるの?
otakakot
1
960
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
1k
Go で作った CLI ツールにバージョンを埋め込みたい
otakakot
0
220
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
570
組込みだけじゃない! TinyGo で始める無料クラウド開発入門
otakakot
1
130
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
1
3.8k
SQLBoiler がメンテナンスモードになりまして
otakakot
0
340
Wasm わからないけど Go で実装したいから入門する
otakakot
1
11k
cmp.Or に感動した
otakakot
3
1.1k
Other Decks in Programming
See All in Programming
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
2
400
開発体験を左右するライブラリの API 設計 - GraphQL スキーマ構築ライブラリから考える #tskaigi
izumin5210
2
280
空間オーディオの活用
objectiveaudio
0
160
My daily life on Ruby
a_matsuda
3
420
AlarmKitで明後日起きれるアラームアプリを作る
trickart
0
140
SkillsをS3 Filesに置く時のあれこれ
watany
3
1.7k
Are We Really Coding 10× Faster with AI?
kohzas
0
210
ビジネスモデルから紐解く、AI+型駆動開発
hirokiomote
2
710
ECR拡張スキャンでSBOMを収集して サプライチェーン攻撃の影響調査を 爆速で終わらせてみた
akihisaikeda
1
170
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
250
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
240
inferと仲良くなる10分間
ryokatsuse
1
150
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.6k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
750
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
190
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Raft: Consensus for Rubyists
vanstee
141
7.4k
Design in an AI World
tapps
1
210
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
260
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
360
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
190
We Are The Robots
honzajavorek
0
230
Prompt Engineering for Job Search
mfonobong
0
310
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. いい距離感でテストと付き合っていこうね