kedacore / keda

KEDA is a Kubernetes-based Event Driven Autoscaling component. It provides event driven scale for any container running in Kubernetes
https://keda.sh
Apache License 2.0
8.32k stars 1.05k forks source link

Test ScaledObject and ScaledJob Controllers #1008

Closed zroubalik closed 2 years ago

zroubalik commented 4 years ago

We should use envtest test framework to test our controllers.

The current test file is just a stub: https://github.com/kedacore/keda/blob/950c5e16deb143a8201189ec7430f7350d0fa6bd/controllers/suite_test.go

zroubalik commented 4 years ago

@TsuyoshiUshio do you think this is something that you can use to migrate and extend your ScaleJob Mock based tests to?

TsuyoshiUshio commented 4 years ago

Hi @zroubalik For the individual unit testing some mock mechanism is required. However, if you want to go with ginkgo, we can change the assertion part. https://github.com/kedacore/keda/blob/v2/pkg/scaling/executor/scale_jobs_test.go#L44 I also considered to use the framework, however, it is great for controller logic validation, however it looks integration testing for the controller. We might need to something for simple unit testing for each part. For example, executor/scale_jobs , we might want to write a test as unit testing for each classes, right? However, this is just my opinion and I might misunderstand the framework. If we can write any unit testing, I'm happy about it. I agree with use the framework! Also we need a tool for unit testing for individual testing. BTW, I used to read unit testing document on the operator sdk official side. However, I can't find it now. I 'd like to read it to understand the framework. Do you know where it is?

zroubalik commented 4 years ago

Thanks for the info. I haven't had a time to look at both frameworks closely, so don't know the details. So might be worth exploring if we can merge both unit and integration tests under one framework. If you think that it is ok, we can keep the current state for now.

zroubalik commented 4 years ago

wrt testing I have found just this: https://sdk.operatorframework.io/docs/building-operators/golang/project_migration_guide/#migrate-your-tests https://book.kubebuilder.io/reference/writing-tests.html

They have changed the docs for the recent version

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically closed due to inactivity.