dotnet-kube-client icon indicating copy to clipboard operation
dotnet-kube-client copied to clipboard

Integration tests

Open felixfbecker opened this issue 6 years ago • 12 comments

Bugs like #51 could be prevented by having tests that run against an actual Kubernetes cluster. This would catch wrong assumptions like return types of certain endpoints.

It's a fair amount of work to get right, but I actually already have this set up for PSKubectl. It runs minikube in Travis, kubectl apply's test resources, runs commands and then does assertions against output of kubectl -o json. Tests are written in PowerShell with Pester which makes interacting with kubectl very easy.

Alternatively we could just consider PSKubectl an external test suite of this, maybe even trigger a build on every published version from a branch. Or CI here could run the test suite of PSKubectl by cloning the GitHub repo.

felixfbecker avatar Dec 17 '18 13:12 felixfbecker

I love this idea - hadn’t had time to do it before but I agree it’s totally worth doing :)

I’ll take a look at PSKubectl’s scripts to see what it would take to set this up (external test suite is a good option, I think, as I don’t expect it to be quick to run?)

tintoy avatar Dec 17 '18 17:12 tintoy

It's fairly quick actually. Booting up Minikube takes a bit (45s), but every test is faster than you'd think. It kubectl apply's the resources before every test and uses e.g. a deployment of a hello world docker image with imagePullPolicy: IfNotPresent, so recreating pods takes about a second before every test.

felixfbecker avatar Dec 17 '18 17:12 felixfbecker

Had a quick look over your CI scripts - that all looks pretty achievable, especially since you’ve done most of the hard work already :)

tintoy avatar Dec 18 '18 10:12 tintoy

I guess the only tricky bit would be cleaning up after each test :)

Maybe a decorator for IXXXClientVX that captures names of resources created so we can run kubectl delete after the test is complete?

tintoy avatar Dec 18 '18 10:12 tintoy

What do you need to cleanup? The next test will just kubectl apply the resources again so they get reset

felixfbecker avatar Dec 18 '18 10:12 felixfbecker

kubectl apply --prune also deletes resources

felixfbecker avatar Dec 18 '18 10:12 felixfbecker

What about tests that use the client to create resources?

I guess I could just write a script to delete all resources in a given namespace or something...

tintoy avatar Dec 18 '18 10:12 tintoy

For gets or deletes though, yeah, it’d be fine.

tintoy avatar Dec 18 '18 10:12 tintoy

As said kubectl apply --prune should delete all resources that are not present in the input YAML afaik

felixfbecker avatar Dec 18 '18 10:12 felixfbecker

Oh - interesting, I hadn’t heard of that usage but that would do the trick :)

tintoy avatar Dec 18 '18 10:12 tintoy

Ah, apparently that only removes resources created by kubectl apply (not ones created by the client). Still, sounds useful :)

tintoy avatar Dec 18 '18 10:12 tintoy

kubectl delete --all deletes all resources in a namespace :)

felixfbecker avatar Dec 18 '18 10:12 felixfbecker