cloudstack icon indicating copy to clipboard operation
cloudstack copied to clipboard

Introducing Hamcrest API to simplify assertion in ImplicitPlannerTest

Open Codegass opened this issue 2 years ago • 11 comments

Description

Fix #6659

This PR introduces Hamcrest API to simplify assertion in ImplicitPlannerTest.checkStrictModeWithCurrentAccountVmsPresent, ImplicitPlannerTest.checkStrictModeHostWithCurrentAccountVmsFull, and ImplicitPlannerTest.checkPreferredModePreferredHostAvailable.

Take ImplicitPlannerTest.checkStrictModeWithCurrentAccountVmsPresent as example: Before Refactoring

...
        boolean foundNeededCluster = false;
        for (Long cluster : clusterList) {
            if (cluster != 1) {
                fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
            } else {
                foundNeededCluster = true;
            }
        }
        assertTrue("Didn't find cluster 1 in the list. It should have been present", foundNeededCluster);
...

After Refactoring

import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat; // org.junit.Assert.assertThat has been deprecated
...
        assertThat("Found cluster that shouldn't have been present, only cluster 1 should have been present",
                            clusterList, everyItem(equalTo(1L)));
...

Types of changes

  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] Enhancement (improves an existing feature and functionality)
  • [ ] Cleanup (Code refactoring and cleanup, that may add test cases)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • [ ] Major
  • [x] Minor

Screenshots (if appropriate):

How Has This Been Tested?

Local cluster environment (KVM, UBUNTU 18.04) runs the test suite.

Codegass avatar Aug 27 '22 05:08 Codegass

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md) Here are some useful points:

  • In case of a new feature add useful documentation (raise doc PR at https://github.com/apache/cloudstack-documentation)
  • Be patient and persistent. It might take some time to get a review or get the final approval from the committers.
  • Pay attention to the quality of your code, ensure tests are passing and your PR doesn't have conflicts.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Issues, Mailing list and Slack.
  • Be sure to read the CloudStack Coding Conventions. Apache CloudStack is a community-driven project and together we are making it better 🚀. In case of doubts contact the developers at: Mailing List: [email protected] (https://cloudstack.apache.org/mailing-lists.html) Slack: https://apachecloudstack.slack.com/

boring-cyborg[bot] avatar Aug 27 '22 05:08 boring-cyborg[bot]

Found UI changes, kicking a new UI QA build @blueorangutan ui

acs-robot avatar Aug 29 '22 17:08 acs-robot

Removed the unwanted reformatting

Codegass avatar Aug 29 '22 17:08 Codegass

@acs-robot a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.

blueorangutan avatar Aug 29 '22 17:08 blueorangutan

UI build: :heavy_check_mark: Live QA URL: http://qa.cloudstack.cloud:8080/client/pr/6676 (SL-JID-2243)

blueorangutan avatar Aug 29 '22 17:08 blueorangutan

It seems the Codecov failed due to some uploading issues. Please let me know if there any action I should take. Thanks🤠

Codegass avatar Aug 31 '22 04:08 Codegass

Found UI changes, kicking a new UI QA build @blueorangutan ui

acs-robot avatar Sep 10 '22 01:09 acs-robot

@acs-robot a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.

blueorangutan avatar Sep 10 '22 01:09 blueorangutan

UI build: :heavy_check_mark: Live QA URL: http://qa.cloudstack.cloud:8080/client/pr/6676 (SL-JID-2330)

blueorangutan avatar Sep 10 '22 02:09 blueorangutan

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Sep 10 '22 02:09 sonarqubecloud[bot]

Codecov Report

Merging #6676 (e8f168a) into main (c526244) will increase coverage by 0.02%. The diff coverage is n/a.

@@             Coverage Diff              @@
##               main    #6676      +/-   ##
============================================
+ Coverage      5.87%    5.90%   +0.02%     
- Complexity     3934     3945      +11     
============================================
  Files          2454     2454              
  Lines        242683   242749      +66     
  Branches      37978    37991      +13     
============================================
+ Hits          14261    14323      +62     
+ Misses       226843   226842       -1     
- Partials       1579     1584       +5     
Impacted Files Coverage Δ
...dstack/storage/datastore/PrimaryDataStoreImpl.java 2.25% <0.00%> (-0.09%) :arrow_down:
...visor/vmware/manager/VmwareStorageManagerImpl.java 1.06% <0.00%> (-0.03%) :arrow_down:
...ne/schema/src/main/java/com/cloud/host/HostVO.java 15.04% <0.00%> (ø)
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 0.00% <0.00%> (ø)
...chema/src/main/java/com/cloud/vm/VMInstanceVO.java 24.40% <0.00%> (ø)
...n/java/com/cloud/resource/ResourceManagerImpl.java 0.00% <0.00%> (ø)
...main/java/com/cloud/service/ServiceOfferingVO.java 18.70% <0.00%> (ø)
...oud/hypervisor/vmware/resource/VmwareResource.java 0.00% <0.00%> (ø)
...esource/VmwareSecondaryStorageResourceHandler.java 0.00% <0.00%> (ø)
...cloud/storage/resource/VmwareStorageProcessor.java 0.32% <0.00%> (+<0.01%) :arrow_up:
... and 17 more

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Sep 12 '22 10:09 codecov[bot]

Hi guys, I just jump to ask if there is still something I need to improve to merge PR? If so, please let me know. Thanks😃

Codegass avatar Nov 04 '22 14:11 Codegass

no @Codegass , merging

DaanHoogland avatar Nov 04 '22 20:11 DaanHoogland