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

[WiP] OSD-20504: Add test case for config's get subcommand #404

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

TheUndeadKing
Copy link

What type of PR is this?

unit-test

What this PR does / Why we need it?

Adding test case for config's get subcommand

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 27, 2024
@openshift-ci-robot
Copy link

openshift-ci-robot commented Apr 27, 2024

@TheUndeadKing: This pull request references OSD-20504 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.16.0" version, but no target version was set.

In response to this:

What type of PR is this?

unit-test

What this PR does / Why we need it?

Adding test case for config's get subcommand

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link
Contributor

openshift-ci bot commented Apr 27, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: TheUndeadKing
Once this PR has been reviewed and has the lgtm label, please assign cblecker for approval. For more information see the Kubernetes Code Review Process.

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

Needs approval from an approver in each of these files:

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

@TheUndeadKing
Copy link
Author

  • In Config folder, we've get.go, set.go & troubleshoot.go. We've test suite for troubleshoot.go, which cover 60%.
  • The get & set func only return error.
// Get func
func getConfig(cmd *cobra.Command, args []string) error {

// Set func
func setConfig(cmd *cobra.Command, args []string) error { 

I tried to write test case[load value for backplane url & doesn't load any value for  backplane url] for get function. In both test case the error return as nil.

// O/P:
url: https://backplane.example.com 
Return value:  <nil>
[..]
url:  
Return nil:  <nil>

@TheUndeadKing TheUndeadKing changed the title OSD-20504: Add test case for config's get subcommand [WiP] OSD-20504: Add test case for config's get subcommand Apr 27, 2024
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 27, 2024
@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 45.81%. Comparing base (03a4452) to head (ec57f92).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #404      +/-   ##
==========================================
+ Coverage   45.66%   45.81%   +0.14%     
==========================================
  Files          78       78              
  Lines        6160     6160              
==========================================
+ Hits         2813     2822       +9     
+ Misses       2997     2987      -10     
- Partials      350      351       +1     

see 1 file with indirect coverage changes

It("Get backplane url return value", func() {
mockOcmInterface.EXPECT().GetOCMEnvironment().Return(ocmEnv, nil).AnyTimes()
err := getConfig(cmd, []string{"url"})
fmt.Println("Return value: ", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need a return value to be printed in test.

It("Get backplane url return nil", func() {
mockOcmInterface.EXPECT().GetOCMEnvironment().Return(ocmEnvNil, nil).AnyTimes()
err := getConfig(cmd, []string{"url"})
fmt.Println("Return nil: ", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need a return value to be printed in test.


ocmEnvNil, _ := cmv1.NewEnvironment().BackplaneURL("").Build()

cmd := &cobra.Command{Use: "get"}
Copy link
Contributor

Choose a reason for hiding this comment

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

The cmd variable could be initialized within the BeforeEach block to ensure that each test case starts with a fresh instance which could prevent potential side effects from previous tests.

Copy link
Author

Choose a reason for hiding this comment

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

If i declare cmd inside before each block, it's not been exported as global variable. i.e, can't use it in the test case

Copy link
Contributor

openshift-ci bot commented Jul 18, 2024

@TheUndeadKing: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@xiaoyu74
Copy link
Contributor

xiaoyu74 commented Sep 3, 2024

@TheUndeadKing - Are you still working on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants