2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Operator SDK のテスト戦略概要

Posted at

(update 2023-07-18: 自分用メモとして公開)

Go のテスト一般論

  • ランタイムにテストが最初から組み込まれている (go test)
  • 「assertion を使わず、Table Driven Test を実装する」のが基本戦略
  • ではあるのだが、BDD (Behaviour Driven Development) したい人が多いので、Ginkgo (BDDフレームワーク) と Gomega (assertionライブラリ) も広く使われている
  • Ginkgo で Table Driven Test することもできる (参考: GinkgoのDesrcibeTableの使い方 - Qiita)

Operator をテストするのに特有な事態

  • 単体テストはともかく、統合テストは kube API Server がないと実行できない/さりとて実際に Kube をテストのたびに立てるのは(kindやminikubeといえども)負荷が大きい
  • そこで Operator SDK が取っている戦略 は?
    1. controller-runtime が提供する envtest というツールで、Kube API Server と Etcd だけは立てる(scheduler はないので、まるきり kube そのものと同じ動きをする、というわけではない点に注意、例えば Deploymentを作ってもそれに伴う Pod は生成されない)
    2. Ginkgo/Gomega を使ったテストコードのテンプレートを自動生成してくれて、make test 一発でテストできるような状態にしてくれる

参考文献

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?