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

cs.RewriteConstants: define error MissingConstantsError #904

Merged
merged 1 commit into from
Jan 17, 2023

Conversation

alban
Copy link
Contributor

@alban alban commented Jan 17, 2023

RewriteConstants can return the error "spec is missing one or more constants" if the constant given as parameter does not exist. This patch defines the error as a specific type so it can be tested with:

    var mErr *MissingConstantsError
    if !errors.As(err, &mErr) {

New unit tests are added, for both the success and failure cases.

Tested with:

    go test -exec sudo -run TestCollectionRewriteCon  ./...

Signed-off-by: Alban Crequy albancrequy@linux.microsoft.com


This PR was suggested by @mauriciovasquezbernal in inspektor-gadget/inspektor-gadget#1201 (comment) to avoid testing with

strings.Contains(err.Error(), "spec is missing one or more constants")

Supersedes #902

RewriteConstants can return the error "spec is missing one or more
constants" if the constant given as parameter does not exist. This patch
defines the error as a specific type so it can be tested with:

    var mErr *MissingConstantsError
    if !errors.As(err, &mErr) { ... }

New unit tests are added, for both the success and failure cases.

Signed-off-by: Alban Crequy <albancrequy@linux.microsoft.com>
Co-developed-by: Lorenz Bauer <oss@lmb.io>
@lmb lmb merged commit 63a3cae into cilium:master Jan 17, 2023
@lmb
Copy link
Collaborator

lmb commented Jan 17, 2023

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants