Karate pathMatches exclusion - karate

I would like to have possibility in Karate to match all paths except /example/path, to have something like this:
pathMatches ('!/example/path')
Is there such possibility?

You can use the requestUri variable which will be always set automatically. The nice thing about the design is you can use "normal" Java Script and achieve any combination you want, pathMatches() is just pre-defined for convenience.
So this should get you what you want, try it !
Scenario: !requestUri.startsWith('/example/path')
EDIT: silly me, I just realized that you have a much better option, again "because JavaScript". This will work !
Scenario: !pathMatches('/example/path')

Related

regex limitations within live template / can use live-template functions as replacement?

I'm removing builder pattern on multiple places. Following example would help me with the task, but mainly I'd like to learn how to use live templates more.
Preexisting code:
Something s = s.builder
.a(...)
.b(bbb)
.build();
and I'd like to remove it to:
Something s = new Something();
s.setA(...);
s.setB(bbb);
part of it can be trivially done using intellij regex, pattern: \.(.*)$ and replacement .set\u$1. Well it could be improved, but lets keep it simple.
I can create surround live template using variable:
regularExpression(SELECTION, "\\.(.*)", "\\u$1")
but \\u will be evaluated as u.
question 1: is it possible to get into here somehow \u functionality?
but I might get around is differently, so why not try to use live temlate variable:
regularExpression(SELECTION, "\\.(.)(.*)", concat(capitalize($1), "$2"))
but this does not seem to work either. .abc is replaced to bc
question 2: why? How would correct template look like? And probably, if it worked, this would behave incorrectly for multiline input. How to make it working and also for multiline inputs?
sorry for questions, I didn't find any harder examples of live templates than trivial replacements.
No, there is no \u functionality in the regularExpression() Live Template macro. It is just a way to call String.replaceAll(), which doesn't support \u.
You can create a Live Template like this:
set$VAR$
And set the following expression for the $VAR$ variable:
capitalize(regularExpression(SELECTION, "\\.(.*)", "$1"))

How to filter by tag in Jaeger

When trying to filter by tag, there is a small popup:
I have been looking for logfmt around, but all I can find is key=value format.
My questions are:
Is there a way for something more sophisticated? (starts_with, not equal, contains, etc)
I am trying to filter by url using http.url="http://example.com?bla=bla&foo=bar". I am pretty sure the value exists because I am copy/pasting from my trace. I am getting no results. Do I need to escape characters or do something else for this to work?
I did some research around logfmt as well. Based on the documentation of the original implementation and in the Python implementation of the parser (and respective tests), I would say that it doesn't support anything more sophisticated (like starts_with, not equal, contains). And this is because the output of the parser is a simple dictionary (with no regex involved in the values).
As for the second question, using the same mentioned Python parser, I was able to double-check that your filter looks fine:
from logfmt import parse_line
parse_line('http.url="http://example.com?bla=bla&foo=bar"')
Output:
{'http.url': 'http://example.com?bla=bla&foo=bar'}
This makes me suspect of an issue on the Jaeger side, but this is as far as I could go.

Chai.js - Check if string contains substring from a list

I'm using chai.js writing some automation tests. I have a string:
url(http://somewhere.com/images/myimage.png)
I want to do something like:
expect(thatSelectedItem).contains.any('jpg', 'png', 'gif')
However can't seem to find anything in chai.js
Any have any suggestions - read the page http://chaijs.com/api/bdd/ however no luck.
Any help appreciated.
Thanks.
With plain Chai (no additional plugins), you can use match:
expect(thatSelectedItem).to.match(/(?:jpg|png|gif)/)
expect(thatSelectedItem).to.contain.oneOf(['jpg', 'png', 'gif'])
This lands with v4.3.0 (docs). oneOf can be chained with contain, contains, include and includes, which will work with both arrays and strings. It's strongly recommended to use because the error messages you get with it are much cleaner.

What is the best naming conventions for XAML namespaces?

Which type of naming is better to use in XAML:
xmlns:inventoryControls="clr-namespace:Inventory.Components.Controls;assembly=Inventory.Components"
Then use it like this:
<inventoryControls:AdvancedTextBox/>
xmlns:ic="clr-namespace:Inventory.Components.Controls;assembly=Inventory.Components"
Then use it like this:
<ic:AdvancedTextBox/>
If you recommend the second way please consider about duplicates in first letter of the namespaces for example may be I wana refere to "Inventory.Components" namespace.
This is the second approach problem example:
xmlns:inventoryControls="clr-namespace:Inventory.Components.Controls;assembly=Inventory.Components"
xmlns:inventoryComponents="clr-namespace:Inventory.Components;assembly=Inventory.Components"
Write either what you like better or what your team agrees is the better option.
My personal opinion is to use some shortening: In XAML, you have to always specify the namespace and writing the whole name every time causes long lines and doesn't help readability much.
But that doesn't mean you have to shorten to just the initials, especially if that causes conflicts. In your cause I would use iCtrls and iComps or iControls and iComponents.

obfuscated way to get "0" in a tcl function, cross platform?

I haven't used tcl before and just need to do one trick, I can do it trivially in something like bash but I need it to work cross-platform (e.g. tcl in cygwin on windows).
Can someone suggest a short (5-10) obfuscated function that just returns 0 after taking two string args? It just can't do something like run shell commands that won't work under Mac/Cygwin.
fwiw, why do this: buying some time in writing a test- the thing generating one of the files is broken but I can't change it, making a hack in the TCL test script until I make extensive changes to use a different 'test core' that isn't broken. For now just declare the first file as 'good' if it exists.
I don't understand the requirement for obfuscation, but the simplest way to create a command that takes two arguments and returns 0 is this:
proc theCommandName {firstArgument secondArgument} {
return 0
}
There are all sorts of ways of making things obscure (e.g., a regular expression that doesn't actually match anything, a complicated expression) but as I said before, I don't understand the requirement in that area; I always try to make my code be the simplest thing that could possibly work…