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
5
8.4k
Goのinterfaceを使って外部サービスに依存しないテストを書く #go #golang / mock external service with golang interface
Toshinori Sugita
May 28, 2018
Tweet
Share
More Decks by Toshinori Sugita
See All by Toshinori Sugita
50以上のマイクロサービスを支えるアプリケーションプラットフォームの設計・構築の後悔と進化 #CNDW2024 / regrets and evolution of application platform
toshi0607
5
5.1k
OPA and cloud resources
toshi0607
0
13k
KompalWeather: Serverless Sauna Service with Cloud Run
toshi0607
0
12k
Knativeで作るDIY FaaS / serverless days fukuoka 2019 knative workshop
toshi0607
0
5k
Knativeで作るDIY FaaS / serverless days tokyo 2019 knative workshop
toshi0607
4
11k
Knativeへの誘い / Go Go Knative!
toshi0607
3
5.5k
Build serverless application on top of Kubernetes #sdmel19
toshi0607
1
6.2k
Knativeで実現するKubernetes上のサーバーレスアーキテクチャ #CNDT2019 #1E3 / serverless architecture on the top of K8s with Knative
toshi0607
9
15k
技術書典で高めるせんとう力 #エンジニア銭湯 / Tech book fest loves sauna
toshi0607
1
6.9k
Other Decks in Technology
See All in Technology
Zabbixチョットデキルとは!?
kujiraitakahiro
0
150
ソフトウェア開発現代史: "LeanとDevOpsの科学"の「科学」とは何か? - DORA Report 10年の変遷を追って - #DevOpsDaysTokyo
takabow
0
140
ブラウザのレガシー・独自機能を愛でる-Firefoxの脆弱性4選- / Browser Crash Club #1
masatokinugawa
0
220
改めて学ぶ Trait の使い方 / phpcon odawara 2025
meihei3
1
370
7,000名規模の 人材サービス企業における プロダクト戦略・戦術と課題 / Product strategy, tactics and challenges for a 7,000-employee staffing company
techtekt
0
240
はじめてのSDET / My first challenge as a SDET
bun913
0
130
データベースで見る『家族アルバム みてね』の変遷 / The Evolution of Family Album Through the Lens of Databases
kohbis
4
1.1k
OPENLOGI Company Profile
hr01
0
62k
Spice up your notifications/try!Swift25
noppefoxwolf
2
160
React Server Componentは 何を解決し何を解決しないのか / What do React Server Components solve, and what do they not solve?
kaminashi
6
1.4k
Lightdashの利活用状況 ー導入から2年経った現在地_20250409
hirokiigeta
2
260
さくらの夕べ Debianナイト - さくらのVPS編
dictoss
0
170
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Bash Introduction
62gerente
611
210k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
21k
Why Our Code Smells
bkeepers
PRO
336
57k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
We Have a Design System, Now What?
morganepeng
52
7.5k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.4k
How to Think Like a Performance Engineer
csswizardry
22
1.5k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.3k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Embracing the Ebb and Flow
colly
85
4.6k
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を使って 外部サービスに依存しないテストを書く