Cucumber/Behave & reading files?

Hey there,

I'm quite new to this part of sw testing, but I need to write some behave/cucumber tests to read some text files.

From all the examples I've see, there's much more in the realm of browser-based testing, so I haven't been able to find much for analyzing text files. Any code snippets/samples that I can use as a starting point?

Any help appreciated!

.

EDIT: As an example, if I wanted to read a terraform file (e.g.: main.tf, or the tfplan in json format) and scanning for something like ACL: "public-read" on an s3 bucket resource)

Posted Apr 9, 2020, 12:57 PM UTC · edited

32
menge101•
When I read file '/Users/you/path/to/file.txt'

@when("I read file '{file_path}'")
def step_impl(context, file_path):
    # do python stuff to read a file

You can do it as a given

Given I have read '/whatever/file.txt'
When I analyze that file
Then I expect things

the given is very much like the when above, except you would add what you need to the context

do your analysis in the when, again putting results of that in context

and then check for your expectations in the then.

2
DolpheusOP•

oh nice, this is exactly what I was looking for to get jumpstarted, thank you!

1