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
390
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
710
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
780
Go で作った CLI ツールにバージョンを埋め込みたい
otakakot
0
210
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
550
組込みだけじゃない! TinyGo で始める無料クラウド開発入門
otakakot
1
130
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
1
3.8k
SQLBoiler がメンテナンスモードになりまして
otakakot
0
330
Wasm わからないけど Go で実装したいから入門する
otakakot
1
10k
cmp.Or に感動した
otakakot
3
1.1k
Other Decks in Programming
See All in Programming
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
220
Programming with a DJ Controller — not vibe coding
m_seki
3
140
事業会社でのセキュリティ長期インターンについて
masachikaura
0
260
SkillがSkillを生む:QA観点出しを自動化した
sontixyou
6
3.5k
AI-DLC Deep Dive
yuukiyo
9
4.7k
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
150
AIを導入する前にやるべきこと
negima
2
140
How Swift's Type System Guides AI Agents
koher
0
290
AI時代のPhpStorm最新事情 #phpcon_odawara
yusuke
0
190
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
110
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
Server-Side Kotlin LT大会 vol.18 [Kotlin-lspの最新情報と Neovimのlsp設定例]
yasunori0418
1
180
Featured
See All Featured
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
110
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
190
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
260
Leo the Paperboy
mayatellez
7
1.7k
Automating Front-end Workflow
addyosmani
1370
200k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
The agentic SEO stack - context over prompts
schlessera
0
760
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.5k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
YesSQL, Process and Tooling at Scale
rocio
174
15k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
340
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. いい距離感でテストと付き合っていこうね