kontena / k8s-client

Ruby Kubernetes API client
Apache License 2.0
76 stars 26 forks source link

Testing with Rails #164

Closed vitobotta closed 4 years ago

vitobotta commented 4 years ago

Hi! I'm working on an app that will let users add custom domains, and the app has to create an ingress whenever a custom domain is added, so I'm thinking of using this gem 🙂

How can I test that ingresses are created as expected without using an actual kubernetes environment? Is it possible? Thanks a lot in advance!

kke commented 4 years ago

In a perfect world, your app should not be testing the functionality of it's dependencies and you should just be testing that your app calls the correct methods of them and trust that the libraries have their own test coverage in check.

K8s-client coverage is at 96.71% (14.77 hits/line), but more importantly, it's being used extensively in our own applications such as https://www.kontena.io/pharos/ and https://github.com/kontena/mortar

You can use webmock or such to stub k8s-client api requests, but it does not offer any "kubernetes simulator" for testing.

vitobotta commented 4 years ago

Hi @kke, thanks. I'm a bit paranoid about testing and would like at least one integration test that verifies that an ingress has actually been created as expected, without stubbing on my side. Perhaps I can use vcr to record API interactions during tests. Thanks!