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
Goのinterfaceを使って外部サービスに依存しないテストを書く #go #golang ...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Toshinori Sugita
May 28, 2018
Technology
8.9k
6
Share
Goのinterfaceを使って外部サービスに依存しないテストを書く #go #golang / mock external service with golang interface
Toshinori Sugita
May 28, 2018
More Decks by Toshinori Sugita
See All by Toshinori Sugita
GKEを中心としたマルチプロダクト・マルチリージョン対応アプリケーションプラットフォームの継続的改善 / continuous improvement of GKE based application platform
toshi0607
1
160
組織を巻き込む大規模プラットフォーム移行戦略 〜50+サービスのマルチリージョン・マルチプロダクト化で学んだステークホルダー協働の実践〜 / Platform migration strategy engaging all stakeholders
toshi0607
2
5.9k
文系学部卒ソフトウェアエンジニアが Georgia Techコンピューターサイエンス修士課程で直面したもの / What a Liberal Arts Graduate Software Engineer Faced in Georgia Tech's Computer Science Master's Program
toshi0607
4
1.6k
50以上のマイクロサービスを支えるアプリケーションプラットフォームの設計・構築の後悔と進化 #CNDW2024 / regrets and evolution of application platform
toshi0607
5
9.1k
OPA and cloud resources
toshi0607
1
14k
KompalWeather: Serverless Sauna Service with Cloud Run
toshi0607
1
13k
Knativeで作るDIY FaaS / serverless days fukuoka 2019 knative workshop
toshi0607
1
5.3k
Knativeで作るDIY FaaS / serverless days tokyo 2019 knative workshop
toshi0607
5
11k
Knativeへの誘い / Go Go Knative!
toshi0607
4
5.9k
Other Decks in Technology
See All in Technology
Agents CLI と Gemini Enterprise Agent Platform で マルチエージェント開発が楽しくなる!
kaz1437
0
140
20260428_Product Management Summit_tadokoroyoshiro
tadokoro_yoshiro
12
14k
20年前の「OSS革命」に学ぶ AI時代の生存戦略
samakada
0
470
AgentCore Managed Harness を使ってみよう
yakumo
2
200
ServiceNow Knowledge 26 の歩き方
manarobot
0
140
エージェントスキルを作って自分のインプットに役立てよう
tsubakimoto_s
0
430
Arcana: Production-Ready RAG in Elixir @ ElixirConf EU 2026
georgeguimaraes
0
110
AIコーディング時代における、ソフトウェアサプライチェーン攻撃に対する防衛術(簡易版)
soysoysoyb
0
120
国内外の生成AIセキュリティの最新動向 & AIガードレール製品「chakoshi」のご紹介 / Latest Trends in Generative AI Security (Domestic & International) & Introduction to AI Guardrail Product "chakoshi"
nttcom
4
1.4k
260422_Sansan_Tech_Talk__関西_vol.3_データ活用のリアル__矢田__.pdf
sansantech
PRO
0
120
独断と偏見で試してみる、 シングル or マルチエージェント どっちがいいの?
shichijoyuhi
1
110
The Journey of Box Building
tagomoris
4
3.4k
Featured
See All Featured
Abbi's Birthday
coloredviolet
2
7.2k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
43k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
Context Engineering - Making Every Token Count
addyosmani
9
840
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
320
Git: the NoSQL Database
bkeepers
PRO
432
67k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
340
Transcript
Goのinterfaceを使って 外部サービスに依存しないテストを書く 2018/5/28 Gopher道場#1 LT大会 @toshi0607
自己紹介 • 杉田 寿憲 ◦ Toshinori Sugita ◦ toshi0607 ◦
toshi0607 ◦ toshi0607 • 最近の様子 ◦ Ruby > JavaScript >>> Go >>>>>> C# • 8月にクロアチア旅行することにした
Goで作り直す.gitignore生成コマンド 2018/5/14 Gopher道場最終回 ※https://speakerdeck.com/toshi0607/reinvent-gitignore-command-using-golang
※https://github.com/toshi0607/gig before
※https://github.com/toshi0607/gig before after
今日のお話 • release-tweeterというAPIを作った • 作ったきっかけ • 課題と解決策 • まとめ
今日のお話 • release-tweeterというAPIを作った • 作ったきっかけ • 課題と解決策 • まとめ
release-tweeterとは? ※https://github.com/toshi0607/release-tweeter
release-tweeterとは? ※https://github.com/github/release-tweeter
今日のお話 • release-tweeterというAPIを作った • 作ったきっかけ • 課題と解決策 • まとめ
作ったきっかけ • コマンドの次はAPI作ってみたい • リリースのお知らせ(twitter)も自動化したい • AWS Lambda(Go)とAPI Gateway使ってみたい
AWS LambdaのGoサポート ※https://twitter.com/awscloud/status/953343724909670400
API GatewayとAWS Lambda
今日のお話 • release-tweeterというAPIを作った • 作ったきっかけ • 課題と解決策 • まとめ
課題 CIでテスト回したいけど…
課題 テストを回すたびにtweet
前提 • ChimeraCoder/anaconda(第三者のtwitter clientライブラリ)利用 • URLを差し替えたりはできない(たぶん) • このライブラリも投稿はテストしてない ◦ 自分にDMするテストはしてる
※https://github.com/ChimeraCoder/anaconda
解決策① • 捨てアカ準備
解決策① • 捨てアカ準備 すいませんなんでもないです
解決策② • ライブラリを使わずに再実装
解決策② • ライブラリを使わずに再実装 便利なライブラリ見つけても再実装...
解決策③ • 関数だけ差し替える
解決策③ • 関数だけ差し替える
解決策③ • 関数だけ差し替える
解決策③ • 関数だけ差し替える 差し替えたい対象が増えても1つずつ代入...?
解決策④ • interfaceを活用して差し替える
解決策④ • interfaceを活用して差し替える
解決策④ • interfaceを活用して差し替える
解決策④ • interfaceを活用して差し替える interfaceを満たせば代入可能
ちなみにGitHubでは...
今日のお話 • release-tweeterというAPIを作った • 作ったきっかけ • 課題と解決策 • まとめ
まとめ テストでは外部サービスに依存せずモックしましょう
ご清聴ありがとうございました! Goのinterfaceを使って 外部サービスに依存しないテストを書く