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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
170
組織を巻き込む大規模プラットフォーム移行戦略 〜50+サービスのマルチリージョン・マルチプロダクト化で学んだステークホルダー協働の実践〜 / Platform migration strategy engaging all stakeholders
toshi0607
2
6.1k
文系学部卒ソフトウェアエンジニアが 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.2k
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
Shipping AI Agents — Lessons from Production
vvatanabe
0
290
Agents CLI と Gemini Enterprise Agent Platform で マルチエージェント開発が楽しくなる!
kaz1437
0
190
AI時代における技術的負債への取り組み
codenote
1
1.9k
AgentCore Managed Harness を使ってみよう
yakumo
2
270
AIが自律的に働く時代へ Amazon Quick で実現するAIエージェント紹介
koheiyoshikawa
0
150
AIコーディング時代における、ソフトウェアサプライチェーン攻撃に対する防衛術(簡易版)
soysoysoyb
0
180
Do Vibe Coding ao LLM em Produção para Busca Agêntica - TDC 2026 - Summit IA - São Paulo
jpbonson
3
160
「誰一人取り残されない」 AIエージェント時代のプロダクト設計思想 Product Management Summit 2026
mizushimac
1
2.2k
ServiceNow Knowledge 26 の歩き方
manarobot
0
250
Scovilleモバイルエンジニア募集中.pdf
julienrudin
0
130
AndroidアプリとCopilot Studioの統合
nakasho
0
180
Choose your own adventure in agentic design patterns
glaforge
0
160
Featured
See All Featured
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
360
Being A Developer After 40
akosma
91
590k
How STYLIGHT went responsive
nonsquared
100
6.1k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Odyssey Design
rkendrick25
PRO
2
580
Scaling GitHub
holman
464
140k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
530
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
200
What's in a price? How to price your products and services
michaelherold
247
13k
Paper Plane (Part 1)
katiecoart
PRO
0
6.8k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
730
The Cult of Friendly URLs
andyhume
79
6.9k
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を使って 外部サービスに依存しないテストを書く