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
Toshinori Sugita
May 28, 2018
Technology
9k
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
190
組織を巻き込む大規模プラットフォーム移行戦略 〜50+サービスのマルチリージョン・マルチプロダクト化で学んだステークホルダー協働の実践〜 / Platform migration strategy engaging all stakeholders
toshi0607
2
7.7k
文系学部卒ソフトウェアエンジニアが Georgia Techコンピューターサイエンス修士課程で直面したもの / What a Liberal Arts Graduate Software Engineer Faced in Georgia Tech's Computer Science Master's Program
toshi0607
4
2.1k
50以上のマイクロサービスを支えるアプリケーションプラットフォームの設計・構築の後悔と進化 #CNDW2024 / regrets and evolution of application platform
toshi0607
5
9.7k
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.4k
Knativeで作るDIY FaaS / serverless days tokyo 2019 knative workshop
toshi0607
5
11k
Knativeへの誘い / Go Go Knative!
toshi0607
4
6k
Other Decks in Technology
See All in Technology
タクシーアプリ『GO』の実践的データ活用〜位置情報データの収集とStreamlitでの可視化〜
mot_techtalk
2
200
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
16
5.6k
ボトムアップ文化が強い組織で セキュリティをどう根付かせていくかの現在進行形の話 / Making Security Stick in a Bottom-Up Organization
yamaguchitk333
0
120
モノリス Rails でも日中に rails db:migrate を走らせたい! / Daytime rails db:migrate on Monolithic Rails!
euglena1215
3
400
Forza Horizon 6 のテレメトリ機能で 自動運転に使えそうな学習データを集める話
henjin0
0
120
【CEDEC2026】コードレビュー支援ツール開発から学ぶ:LLMを用いた業務システムの実践的な運用設計と誤出力対策
cygames
PRO
0
530
事業価値と Engineering 2026年度版
recruitengineers
PRO
29
15k
名古屋の市バスGTFS-JPデータ×スガキヤ 最寄りバス停検索をAmazon ElastiCache Serverless for Valkeyで最適化する
usanchuu
1
260
組織にどうSREを根付かせるか?〜IVRyの場合〜
abnoumaru
0
320
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4.9k
plamo-3-translateの開発
pfn
PRO
0
280
AIがAPIを書く時代に、私たちは何を設計すべきか
nagix
0
210
Featured
See All Featured
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
Navigating Team Friction
lara
192
16k
How to Ace a Technical Interview
jacobian
281
24k
Ruling the World: When Life Gets Gamed
codingconduct
0
290
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
650
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
440
Tell your own story through comics
letsgokoyo
1
1k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
570
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
250
Building Flexible Design Systems
yeseniaperezcruz
330
40k
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を使って 外部サービスに依存しないテストを書く