Comments (2)
Hi, thanks ;)
It does not relate to godog and instead - is a design issue and you should manage your state and control it from tests the same as with godog. You can implement this in many ways, for example.
- in main func read used environment variables to config struct and in test case change it in before scenario hook. It would require to pass config values for functions which needs these parameters
- Another way, would be to export and unset these variables in after scenario hook.
The example for the second, which is easier but not better design solution, would be:
Feature: user authentication
In order to access my private resources
As an anonymous user
I need to be able to authenticate
Scenario: private resources are restricted from wrong credentials
Given my credentials are "username" and "password"
When I send "GET" request to "/v1/requires/auth"
Then the response code should be 403
Scenario: I should be able to access private resource with good credentials
Given there is user "john" with password "secret"
And my credentials are "john" and "secret"
When I send "GET" request to "/v1/requires/auth"
Then the response code should be 200
Where my credentials are step, could set environment variables:
func myCredentialsAre(user, passw string) error {
os.Setenv("AUTH_USER", user)
os.Setenv("AUTH_PASS", passw)
return nil
}
Given there is user step, should allow to pass these credentials, some state in storage or memory to pass authentication with correct credentials.
After the scenario, you should unset the environment:
// s is godog suite
s.AfterScenario(func(_ interface{}, _ error) {
os.Unsetenv("AUTH_USER")
os.Unsetenv("AUTH_PASS")
})
Note, this solution won't work with concurrent tests. So better is to have something like configuration structure instead of os environment directly..
from godog.
Totally makes sense, thanks alot for the details !
from godog.
Related Issues (20)
- Support for Go 1.20
- runAfterScenarioHooks invoke twice when step failed that is not the last step HOT 4
- Enhancement to allow to skip a test from the code HOT 8
- Background Outline HOT 2
- Setting option `Concurrency = 2` fails when running the Example HOT 1
- click on run tests but tests are not running HOT 1
- Please update the concurrency paragraph in the docs to clarify if scenario outlines run in parallel or only the scenarios HOT 1
- Is this feature file in godog/_examples/godogs running sequencially ? HOT 2
- Why Getting total scenarios as 6 while I am having total 5 scenarios HOT 3
- Skipping a test by returning `godog.ErrSkip` does not work? HOT 4
- print error stack when panic
- step function support return a nil Context with error HOT 1
- Conflict between global flags set by godog.BindCommandLineFlags and spf13/cobra HOT 1
- HELP: I want to know the index of a scenario in a scenario outline in the before scenario hook.
- Can't navigate to step definition from Gherkin step
- Unexpected step line values in cucumber report generated by Godog for scenario outlines
- ReadMe add step `go get ...` see provided patch to fix it
- Tag Filtering Expressions HOT 2
- Calculated step duration is wrong HOT 3
- Support for attachments / embeddings as per Cucumber and Behave HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godog.