Skip to content
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

Open
dsinecos opened this issue Jul 26, 2021 · 4 comments

Comments

@dsinecos
Copy link

Software versions

  • OS: Ubuntu 20.04
  • Consumer Pact library: pact-go v2.0.0-20210621102432-26b32fd1552a
  • Provider Pact library: -
  • Golang Version: go1.16.2 linux/amd64
  • Golang environment: -

Expected behaviour

When running contract tests using go test, presently I need to either manually delete the pact directory or configure a Before 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") to pact.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

@mefellows
Copy link
Member

Thanks for this, I'll look at this on my next OSS day.

@YOU54F YOU54F added the good first issue Indicates a good issue for first-time contributors label Sep 4, 2024
@YOU54F
Copy link
Member

YOU54F commented Sep 4, 2024

So I think the original defect

when I change the text inside matchers eg. pact.S("Original text") to pact.S("Changed text"). It doesn't get updated in the generated pact files.

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

@YOU54F YOU54F removed the good first issue Indicates a good issue for first-time contributors label Sep 4, 2024
@mefellows
Copy link
Member

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).

@YOU54F
Copy link
Member

YOU54F commented Nov 19, 2024

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/...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants