-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration to automatically delete pact
directory when re-running contract tests
#173
Comments
Thanks for this, I'll look at this on my next OSS day. |
So I think the original defect
is the same as listed in pact-foundation/pact-reference#77 fixed by commit pact-foundation/pact-reference@3acf437 I can't see anything in the shared core for deleting files prior to a test run |
Yeah it might be, I can't remember what I was thinking so far back. The core doesn't know when the testing starts or finishes - each interaction is effectively tested on its own (it gets its own mock server, for example). Probably any cleaning would need to happen in the client or by the user (current recommendation). |
So you can do a pre-test in your Go code. Here I am scoping it with a consumer build tag, so it runs before our consumer tests, but not before our provider tagged tests. //go:build consumer
// +build consumer
package main
import (
"os"
"testing"
)
func TestMain(m *testing.M) {
// Remove specific files before running tests
if err := os.RemoveAll("pacts"); err != nil {
panic(err)
}
// Run tests
code := m.Run()
// Exit with the test result code
os.Exit(code)
} This will clear pacts prior to a run go test -v -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/... This won't go test -v -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/... |
Software versions
Expected behaviour
When running contract tests using
go test
, presently I need to either manually delete the pact directory or configure aBefore
hook to delete the pact directory. If I don't do this certain changes will not be overwritten when re-running the pact tests.For eg. when I change the text inside matchers eg.
pact.S("Original text")
topact.S("Changed text")
. It doesn't get updated in the generated pact files. I need to delete the pact folder and rerun the tests for these changes to take effect.Actual behaviour
Based on a conversation with Matt in slack ( Refer for conversation ) the functionality to automatically delete the pact directory exists in the shared core. The configuration will have to be exposed.
This configuration will automatically delete the pact directory on rerunning the contract tests.
Steps to reproduce
Relevent log files
The text was updated successfully, but these errors were encountered: