Skip to content

Regular expression matching not working as expected #46

Closed
@luishernandezv

Description

I'm having an issue with regular expressions matching with Bats 1.11.0 in macOS Sonoma 14.5.

Say you have the following resources

kubectl get pods -n foo                                                                                                                              
NAME                                                      READY   STATUS    RESTARTS   AGE
my-pod-5fcfc99f7-hnt5x                      1/1     Running   0          119m

And the following test:

load "lib/utils"
load "lib/detik"

DETIK_CLIENT_NAME="kubectl"
DETIK_CLIENT_NAMESPACE="foo"

@test "should find pods" {
    try "at most 1 times every 5s to get pod named '^my-pod-[a-z0-9]{9,10}-[a-z0-9]{5}$' and verify that 'status' is 'running'"
}

This test would fail with no matches found.

Now I see that in this line the grep is not using extended regular expressions which might be partially the cause of this issue. I have verified that is not just adding -E to that grep to make it work since using the $ to match to the end of the line would still cause some issues

Look at the return of the eval

eval kubectl --namespace=foo get pod -o custom-columns=NAME:.metadata.name,PROP:.status.phase 
# my-manager-5fcfc99f7-hnt5x               Running

My question is, is this expected behaviour? If it is, should it be added to the docs?

Also one thing I noticed is that using the examples for the Regex in the docs using multi line will result in Invalid expression: it does not respect the expected syntax.

Thanks.

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions