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
Kotaro Otaka
October 24, 2024
Programming
380
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
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
630
Go で作った CLI ツールにバージョンを埋め込みたい
otakakot
0
200
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
540
組込みだけじゃない! TinyGo で始める無料クラウド開発入門
otakakot
1
120
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
1
3.8k
SQLBoiler がメンテナンスモードになりまして
otakakot
0
320
Wasm わからないけど Go で実装したいから入門する
otakakot
1
10k
cmp.Or に感動した
otakakot
3
1k
無料で楽しむ Go サーバー開発のススメ
otakakot
11
4.2k
Other Decks in Programming
See All in Programming
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
4
1.5k
存在論的プログラミング: 時間と存在を記述する
koriym
5
750
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1.3k
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
130
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.5k
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
140
RSAが破られる前に知っておきたい 耐量子計算機暗号(PQC)入門 / Intro to PQC: Preparing for the Post-RSA Era
mackey0225
3
110
Redox OS でのネームスペース管理と chroot の実現
isanethen
0
500
事業会社でのセキュリティ長期インターンについて
masachikaura
0
200
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
540
今こそ押さえておきたい アマゾンウェブサービス(AWS)の データベースの基礎 おもクラ #6版
satoshi256kbyte
1
220
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
1.3k
Featured
See All Featured
Mind Mapping
helmedeiros
PRO
1
140
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
630
Producing Creativity
orderedlist
PRO
348
40k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
250
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
160
Discover your Explorer Soul
emna__ayadi
2
1.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
190
The browser strikes back
jonoalderson
0
870
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
230
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
120
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
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. いい距離感でテストと付き合っていこうね