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

Allow more than one skip functions per check. #1645

Conversation

greyerof
Copy link
Contributor

The check.WithSkipFn(skipFunc) has been replaced by a variadic func version to allow more than one skip functions to be called: check.WithSkipFn(skipFunc1, skipFunc2...)

By default, the check will be skipped if any skip function returns true when they're called (which happens before running the CheckFn).

If we need to skip the check in case all the skip functions return true, the check.WithSkipModeAll() needs to be used.

Examples:

  1. Skip check if no deployments or no statefulsets were found (testhelper.SkipIfEmptyAny()):
check := checksdb.NewCheck(id, labels).
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  WithCheckFn(func() error {
    ..
  })
  1. We want to skip the check if no deployments and no statefulsets were found (testhelper.SkipIfEmptyAll()):
check := checksdb.NewCheck(id, labels).
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  WithSkipCheckModeAll().
  WithCheckFn(func() error {
    ..
  })

The skip functions are appended to a slice in the same order as they're passed to the check.WithSkipCheckFn() calls, and it can be called more than once. E.g.: in the previous examples, this call:

  ...
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  ...

is equal to:

  ...
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env)).
  WithSkipCheckFn(testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  ...

Extra changes:

  • Added recovery mechanism from panic when running the skip functions, similar to the beforeX/afterX ones.
  • Added helper skip func creators in the testhelper package for no CRDs, no statefulSets and no deployments found.
  • Adapted the observability ts.

The check.WithSkipFn(func) has been replaced by a variadic func version
to allow more than one skip functions to be called:
check.WithSkipFn(skipFunc1, skipFunc2...)

By default, the check will be skipped if any skip function returns true
when they're called (which happens before running the CheckFn).

If we need to skip the check in case all the skip functions return true,
the check.WithSkipModeAll() needs to be used.

Examples:
1. Skip check if no deployments *or* no statefulsets were found
(testhelper.SkipIfEmptyAny()):
check := checksdb.NewCheck(id, labels).
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  WithCheckFn(func() error {
    ..
  })

2. We want to skip the check if no deployments *and* no statefulsets
were found (testhelper.SkipIfEmptyAll()):
check := checksdb.NewCheck(id, labels).
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  WithSkipCheckModeAll().
  WithCheckFn(func() error {
    ..
  })

The skip functions are appended to a slice in the same order as they're
passed to the check.WithSkipCheckFn() calls, and it can be called more
than once. E.g.: in the previous examples, this call:
  ...
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  ...
is equal to:
  ...
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env)).
  WithSkipCheckFn(testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  ...

Extra changes:
- Added helper skip func creators in the testhelper package for no CRDs,
  no statefulSets and no deployments found.
- Adapted the observability ts.
Copy link
Member

@sebrandon1 sebrandon1 left a comment

Choose a reason for hiding this comment

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

Excellent!

@sebrandon1 sebrandon1 merged commit be56aa9 into redhat-best-practices-for-k8s:ginkgo_removal Nov 20, 2023
8 checks passed
sebrandon1 pushed a commit to sebrandon1/certsuite that referenced this pull request Nov 21, 2023
…for-k8s#1645)

The check.WithSkipFn(func) has been replaced by a variadic func version
to allow more than one skip functions to be called:
check.WithSkipFn(skipFunc1, skipFunc2...)

By default, the check will be skipped if any skip function returns true
when they're called (which happens before running the CheckFn).

If we need to skip the check in case all the skip functions return true,
the check.WithSkipModeAll() needs to be used.

Examples:
1. Skip check if no deployments *or* no statefulsets were found
(testhelper.SkipIfEmptyAny()):
check := checksdb.NewCheck(id, labels).
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  WithCheckFn(func() error {
    ..
  })

2. We want to skip the check if no deployments *and* no statefulsets
were found (testhelper.SkipIfEmptyAll()):
check := checksdb.NewCheck(id, labels).
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  WithSkipCheckModeAll().
  WithCheckFn(func() error {
    ..
  })

The skip functions are appended to a slice in the same order as they're
passed to the check.WithSkipCheckFn() calls, and it can be called more
than once. E.g.: in the previous examples, this call:
  ...
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  ...
is equal to:
  ...
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env)).
  WithSkipCheckFn(testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  ...

Extra changes:
- Added helper skip func creators in the testhelper package for no CRDs,
  no statefulSets and no deployments found.
- Adapted the observability ts.
sebrandon1 pushed a commit to sebrandon1/certsuite that referenced this pull request Nov 21, 2023
…for-k8s#1645)

The check.WithSkipFn(func) has been replaced by a variadic func version
to allow more than one skip functions to be called:
check.WithSkipFn(skipFunc1, skipFunc2...)

By default, the check will be skipped if any skip function returns true
when they're called (which happens before running the CheckFn).

If we need to skip the check in case all the skip functions return true,
the check.WithSkipModeAll() needs to be used.

Examples:
1. Skip check if no deployments *or* no statefulsets were found
(testhelper.SkipIfEmptyAny()):
check := checksdb.NewCheck(id, labels).
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  WithCheckFn(func() error {
    ..
  })

2. We want to skip the check if no deployments *and* no statefulsets
were found (testhelper.SkipIfEmptyAll()):
check := checksdb.NewCheck(id, labels).
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  WithSkipCheckModeAll().
  WithCheckFn(func() error {
    ..
  })

The skip functions are appended to a slice in the same order as they're
passed to the check.WithSkipCheckFn() calls, and it can be called more
than once. E.g.: in the previous examples, this call:
  ...
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env), testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  ...
is equal to:
  ...
  WithSkipCheckFn(testhelper.GetNoDeploymentsUnderTestSkipFn(&env)).
  WithSkipCheckFn(testhelper.GetNoStatefulSetsUnderTestSkipFn(&env)).
  ...

Extra changes:
- Added helper skip func creators in the testhelper package for no CRDs,
  no statefulSets and no deployments found.
- Adapted the observability ts.
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