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

test: added tests for the cmd-filters package #892

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

VaibhavMalik4187
Copy link
Contributor

@VaibhavMalik4187 VaibhavMalik4187 commented Jan 25, 2024

📑 Description

This commit adds new tests for the cmd/filters package. As a result,
the code coverage of the package has increased from 0% to almost 75%

This also includes a minor adjustment in the list command. Now, the list
of the filters will always be in sorted order for better consistency.

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

@VaibhavMalik4187 VaibhavMalik4187 requested review from a team as code owners January 25, 2024 10:49
@VaibhavMalik4187 VaibhavMalik4187 changed the title Added tests for the cmd-filters package test: added tests for the cmd-filters package Jan 30, 2024
@VaibhavMalik4187 VaibhavMalik4187 force-pushed the cmd-filters-tests branch 2 times, most recently from 98dfa72 to 43531d6 Compare January 30, 2024 21:02
@VaibhavMalik4187
Copy link
Contributor Author

@AlexsJones, I've tried to add some tests to the cmd-filters package and a minor modification in the filters list command. Could you please go through this PR whenever you have a moment? Thanks!

@VaibhavMalik4187
Copy link
Contributor Author

@AlexsJones, I've fixed the CI errors.

@VaibhavMalik4187 VaibhavMalik4187 force-pushed the cmd-filters-tests branch 3 times, most recently from ea579a7 to 1a473e7 Compare March 19, 2024 06:15
Copy link
Contributor

@JuHyung-Son JuHyung-Son left a comment

Choose a reason for hiding this comment

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

i have some questions.
overall very good and nice work on sorting filters.

err := addCmd.Args(&cobra.Command{}, []string{"arg1"})
require.NoError(t, err)

err = addCmd.Args(&cobra.Command{}, []string{"arg1", "arg2"})
Copy link
Contributor

Choose a reason for hiding this comment

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

what are these arg1, arg2 values? what will actual values for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it and realized that these are useless, hence, I've got rid of them in the latest version.

cmd/filters/add_test.go Show resolved Hide resolved
cmd/filters/add_test.go Outdated Show resolved Hide resolved
cmd/filters/remove_test.go Outdated Show resolved Hide resolved

// Initially the list contained 12 filters, after deleting one filter in this
// test, now it should be left with 11 filters only.
require.Equal(t, 11, len(viper.GetStringSlice("active_filters")))
Copy link
Contributor

Choose a reason for hiding this comment

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

how about use length of data[active_filters]. it's more safe later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

data is not up to date with the active filters, its sole purpose was to populate the configuration file.

Copy link
Contributor

Choose a reason for hiding this comment

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

i see. but we can do this. len(data['active_filters']) - 1 since we remove one filter

got, _ := io.ReadAll(r)
os.Stdout = rescueStdout

want := "Active: \n> CronJob\n> Deployment\n> HorizontalPodAutoScaler\n> Ingress\n> MutatingWebhookConfiguration\n> Node\n> PersistentVolumeClaim\n> Pod\n> ReplicaSet\n> Service\n> StatefulSet\n> ValidatingWebhookConfiguration\nUnused: \n> Gateway\n> GatewayClass\n> HTTPRoute\n> Log\n> NetworkPolicy\n> PodDisruptionBudget\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

are these default filters?
if so, default filters can vary in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this test is not very useful. I'll remove it soon.

cmd/filters/add_test.go Show resolved Hide resolved
cmd/filters/remove_test.go Show resolved Hide resolved
This commit adds new tests for the `cmd/filters` package. As a result,
the code coverage of the package has increased from 0% to almost 51%

This also includes a minor adjustment in the list command. Now, the list
of the filters will always be in sorted order for better consistency.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
Copy link
Member

@AlexsJones AlexsJones left a comment

Choose a reason for hiding this comment

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

@k8sgpt-ai/k8sgpt-maintainers can someone also review?

// Set the configuration file in viper
configFileName := "delete-config.json"
data := map[string]interface{}{
"active_filters": []string{
Copy link
Contributor

Choose a reason for hiding this comment

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

this has 11 filters not 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Proposed
Development

Successfully merging this pull request may close these issues.

None yet

3 participants