Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEVHAS-491] Mock SPI Client & Devfile Utils Client for Pvt Comp Controller Tests #421

Merged
merged 5 commits into from
Dec 4, 2023

Conversation

maysunfaisal
Copy link
Member

What does this PR do?:

  • Mock SPI Client to handle private Component controller tests
  • Mock Devfile Util Client to hanle private Component controller tests
  • Adds more use cases for private Component controller tests

Which issue(s)/story(ies) does this PR fixes:

https://issues.redhat.com/browse/DEVHAS-491

PR acceptance criteria:

  • Unit/Functional tests

  • Documentation

  • Client Impact

How to test changes / Special notes to the reviewer:

Tests should pass

@maysunfaisal
Copy link
Member Author

Once devfile/library#191 is merged, I should be pull in the latest commit and teh tests should pass.

Signed-off-by: Maysun J Faisal <[email protected]>
pkg/github/mock.go Fixed Show fixed Hide fixed
Copy link

codecov bot commented Nov 30, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (181ed5d) 81.34% compared to head (15f2bd2) 81.26%.

Files Patch % Lines
controllers/component_controller.go 50.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #421      +/-   ##
==========================================
- Coverage   81.34%   81.26%   -0.08%     
==========================================
  Files          32       32              
  Lines        4787     4789       +2     
==========================================
- Hits         3894     3892       -2     
- Misses        702      705       +3     
- Partials      191      192       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -401,7 +403,7 @@ func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
if devfileLocation != "" {
// Parse the Component Devfile
log.Info(fmt.Sprintf("Parsing Devfile from the Devfile location %s... %v", devfileLocation, req.NamespacedName))
compDevfileData, err = cdqanalysis.ParseDevfileWithParserArgs(&devfileParser.ParserArgs{URL: devfileLocation, Token: gitToken})
compDevfileData, err = cdqanalysis.ParseDevfileWithParserArgs(&devfileParser.ParserArgs{URL: devfileLocation, Token: gitToken, DevfileUtilsClient: r.DevfileUtilsClient})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw in component controller, it calls multiple devfile parser. why only pass in DevfileUtilsClient in this place? because the test case only covers here?
also should this be tested in CDQ module as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Question. Because:

  1. This is the only place in component controller which uses URL devfileParser.ParserArgs{URL: devfileLocation ..., other invocations use &devfileParser.ParserArgs{Data: []byte(component.Status.Devfile) ....
  2. https://issues.redhat.com/browse/DEVHAS-492 deals with testing private links in the devfile, so when a Devfile is from a data src and has private links for URI for example, then we can provide DevfileUtilsClient in these calls
  3. Also, devfile/library does a default assignment if its nil, https://github.com/devfile/library/blob/main/pkg/devfile/parser/parse.go#L173-L175. So even if we dont provide argument with the call here, it will always use the real implementation. When we are working on https://issues.redhat.com/browse/DEVHAS-492, we can change it to allow for mock tests.

Copy link
Member Author

@maysunfaisal maysunfaisal Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one potential call in CDQ which may have been missed, let me look into that and open a spike investigation issue, since its out of the scope of this.

Otherwise the remaining CDQ calls are with public registry which we dont need token. Also application controller doesnt need a token because we construct the devfile for application CR.

Source: appstudiov1alpha1.ComponentSource{
ComponentSourceUnion: appstudiov1alpha1.ComponentSourceUnion{
GitSource: &appstudiov1alpha1.GitSource{
URL: SampleRepoLink,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test says for private repo, is this samplerepolink for public repo testing tho?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it doesn't matter what repo we provide here, we are testing the token "valid-token" which returns a mock devfile from See https://github.com/devfile/library/blob/main/pkg/util/mock.go#L250. But I changed this line to a private repo to avoid confusion and added a comment to the mock file. 👍

Copy link

sonarqubecloud bot commented Dec 1, 2023

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 2 Code Smells

No Coverage information No Coverage information
1.9% 1.9% Duplication

Copy link
Contributor

@yangcao77 yangcao77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

Copy link

openshift-ci bot commented Dec 4, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maysunfaisal, yangcao77

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [maysunfaisal,yangcao77]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@maysunfaisal maysunfaisal merged commit d506e22 into redhat-appstudio:main Dec 4, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants