AlfrescoArchive / activiti-cloud-charts

Helm Charts for Activiti cloud Apps
Apache License 2.0
29 stars 28 forks source link

feat: initial common chart helm unit tests [WIP] #56

Open igdianov opened 5 years ago

igdianov commented 5 years ago

This PR will add support for Helm unit tests to keep our charts consistent and robust using https://github.com/lrills/helm-unittest plugin.

This will allow to write test files in pure YAML, render test resource templates locally with no need of tiller while define values and release options for multiple test cases. This will also enable us to apply CI/CD for automating Helm chart PR validation, releases and promotion via updatebot.

$ make verify                                                                                         
helm dep build .                                                                                      
No requirements found in ./charts.                                                                    
helm lint .                                                                                           
==> Linting .                                                                                         
Lint OK                                                                                               

1 chart(s) linted, no failures                                                                        
helm unittest .                                                                                       

### Chart [ common ] .                                                                                

2019/02/25 22:53:05 warning: cannot overwrite table with non table for annotations (map[])            
 PASS  test deployment  tests/deployment_test.yaml                                                    
2019/02/25 22:53:05 warning: cannot overwrite table with non table for annotations (map[])            
2019/02/25 22:53:05 warning: cannot overwrite table with non table for annotations (map[])            
 PASS  test ingress     tests/ingress_test.yaml                                                       

Charts:      1 passed, 1 total                                                                        
Test Suites: 2 passed, 2 total                                                                        
Tests:       5 passed, 5 total                                                                        
Snapshot:    0 passed, 0 total                                                                        
Time:        26.8412ms                                                                                

In case of test error the following output will be produced:

$ make verify                                                                                                              
helm dep build .                                                                                                           
No requirements found in ./charts.                                                                                         
helm lint .                                                                                                                
==> Linting .                                                                                                              
Lint OK                                                                                                                    

1 chart(s) linted, no failures                                                                                             
helm unittest .                                                                                                            

### Chart [ common ] .                                                                                                     

2019/02/25 22:55:57 warning: cannot overwrite table with non table for annotations (map[])                                 
 FAIL  test deployment  tests/deployment_test.yaml                                                                         
        - should pass all kinds of assertion                                                                               

                - asserts[5] `contains` fail                                                                               

                        Path:   spec.template.spec.containers[0].ports                                                     
                        Expected to contain:                                                                               
                                - containerPort: 80                                                                        
                        Actual:                                                                                            
                                - containerPort: 8080                                                                      

                - asserts[6] `notContains` fail                                                                            

                        Path:   spec.template.spec.containers[0].ports                                                     
                        Expected NOT to contain:                                                                           
                                - containerPort: 8080                                                                      
                        Actual:                                                                                            
                                - containerPort: 8080                                                                      

2019/02/25 22:55:57 warning: cannot overwrite table with non table for annotations (map[])                                 
2019/02/25 22:55:57 warning: cannot overwrite table with non table for annotations (map[])                                 
 PASS  test ingress     tests/ingress_test.yaml                                                                            

Charts:      1 failed, 0 passed, 1 total                                                                                   
Test Suites: 1 failed, 1 passed, 2 total                                                                                   
Tests:       1 failed, 4 passed, 5 total                                                                                   
Snapshot:    0 passed, 0 total                                                                                             
Time:        30.6134ms                                                                                                     

Error: plugin "unittest" exited with error                                                                                 
make: *** [verify] Error 1                                                                                                 
ryandawsonuk commented 5 years ago

I can see a greater appeal of this for the common chart as it performs much more logic than the other chart. Common is also a bit less exposed to the changes that could happen related to https://github.com/Activiti/Activiti/issues/2269

Unit tests like these quite coupled to the code. For the runtime bundle and so on they could end up just asserting that the yaml contains what it quite obviously contains by reading the template file. That's more maintenance we should be cautious about if significant changes are coming. I'd say that would require a team decision.