How to compare downloaded file in karate? [duplicate] - karate

This question already has answers here:
How to get the downloaded xlsx file from the api endpoint in karate?
(2 answers)
Closed 1 year ago.
I would like to compare the text file, however the API is returning application/octet-stream which I cannot change currently. That's why karate probably tries to compare the binary and test. That means this:
Given path '/download/testing/'+fileId
When method get
Then status 200
And match response == read('../files/test.txt')
leads to:
match failed: EQUALS
$ | data types don't match (LIST:STRING)
[116,101,115,116,105,110,103]
'testing'
The file test.txt contains just testing. I cannot find the way how to convert string to byte array. I could use probably java function, but at first I would like to find out if there is some built-in function.

You can do type conversions: https://github.com/karatelabs/karate#type-conversion
So this will convert a binary response into text:
* string response = response
That should get you going. The reverse is also possible.
For completeness, note that the responseBytes variable will always contain a copy of the response, but as a byte-array.

Related

Passing double equal sign in value in POSTMAN using raw text body

I'm using POSTMAN to send parameter to an API using raw text format. The data i sent has two equal sign in the end in one of the parameters. Lets say i have a variable a, b, and c. Variable a value is 1234567890==; so i write the full raw text as follow :
a=123456789==&b=1234&c=1234
but the postman didn't recognize the double equal sign at the end of variable a value, so it was like the POSTMAN does not recognized the double equal sign other than the separator between key and value. I tried using the x-form-www-urlencoded body it can send the double equal sign, but when i used raw text format it cannot. I'm required to use the raw text format to send the parameter to the API. How can i fix my problem.
Thank you
I just tried this using postman-echo and the data was sent properly. Check this sample request I've created for you.
As you can see I set the Body to the payload above, with raw text format:
Postman-echo replies exactly with the same payload, which means the server would have gotten the data as is{:

Firestore rules variable in path compare to data

I want to compare a variable in the path with a entry in my document. I build the following rule:
match /{userId}/test/{cycle}/results {
//allow read: if 3 == get(/databases/$(database)/documents/$(userId)/status).data.number
allow read: if cycle == get(/databases/$(database)/documents/$(userId)/status).data.number
}
The commented out line works perfectly which means that the {cycle} variable in my path works and the correct number is transferred but when I want to compare the cycle variable with the number out of the databse it doens't work.
Is it possible that I compare strings with numbers or anything like this???
Thanks!!
I could solve it myself. The problems was that I compared a string with a Number. The path delivered by the request as a string which also defines the {cycle} variable as a string. I compared it with my data from my database which was a number...
Solution, convert the number into a string
match /{userId}/test/{cycle}/results {
allow read: if cycle == string(get(/databases/$(database)/documents/$(userId)/status).data.number)
}
For more: https://firebase.google.com/docs/reference/rules/rules.String

How to use NSLog with data from a server [duplicate]

This question already has answers here:
ios programming - Data argument not used by format string
(2 answers)
Closed 6 years ago.
Hi there I'm trying to do an NSLog but what I want to see is what it's inside of my dictionary like this.
NSLog(#"diccionario", diccionario);
And this warning appears:
Data argument not used by format string
The diccionario object contains data from a server so like I said I want to print in the console the info that diccionario contains, because is not printing anything.
Thanks.
NSLog(#"diccionario : %#", diccionario);
Should be the solution.

Schema of codec is part of the data stream

I'm currently evaluating if scodec is the right tool for my task. I have to parse an InputStream (file or network) which is structured the following:
| Header - FieldDesc1 - FieldDesc2 - ... \
- FieldDescM - Record1 - Record2 - ... - RecordN |
This means the stream starts with some metadata, which descibes what will follow. Each element is separated by a delimiter ( - ) which identifies what type it is. The N field descriptions contain the information which structure and size each of the N records will have.
I was readily able to parse header as well as the sequence of fields, because I was able to formulate a codec which is known at compile time. But I'm kind of puzzled how to build a codec at runtime due to the information from the field descriptions.
Is that possible? If yes, perhaps you can point me to an example?
Here is a starting point if it's still relevant:
Use a DiscriminatorCodec (and a potentially related question), or
Use consume() on the codec decoding the type identifier (which I guess is a simple number), and pass the type to a function returning the correct wanted Codec.
For example using consume(), you can determine what codec to use at decode time:
def variableTypeC =
int8.consume(tid => selectCodec(tid))(selectTypeId(_))
I had to work on a similar problem and went for the consume() solution (as I had the feeling it provided me with a bit more flexbility and was only discovering scodec at the time).
I'd be happy to build an example using DiscriminatorCodec if there is any need for it :).

Unable to correctly interpret format specifiers in resource path

I am trying to retrieve some information from the server via the following objective C resource path. However, I was unable to get my results as the resource path passed to the server is altered as shown below (server console)
//Objective C code
NSString *resourcePath = [NSString stringWithFormat:#"/sm/search?limit=100&term=%#&types%5B%5D=users&types%5B%5D=questions&types%5B%5D=topics",searchString];
//Server console
[GET /sm/search?limit=100&term=Afhd&types5803200164=users&types51107296256=questions&types5368849=topics]
How can I update my code so that the server can recognize the regular expressions (%5B%5D) in my resource path instead of converting them?
As you use stringWithFormat, it means format specifiers start with %.
If you want to leave %5d etc intact in the output, you have to double the percent signs: %%5d.
So, you have to double all of them, except the one in term=%#, so that the value of stringSearch get into the result.