Skip to content

feat: wrappers and test helpers - #41

Merged
pavelsmejkal merged 5 commits into
mainfrom
ps/wrappers
Jun 11, 2026
Merged

feat: wrappers and test helpers#41
pavelsmejkal merged 5 commits into
mainfrom
ps/wrappers

Conversation

@pavelsmejkal

@pavelsmejkal pavelsmejkal commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Please read CONTRIBUTING.md for additional information on contributing to this repository!

What this PR does / why we need it

  • Helpers to make testing easier

  • SavePoints and ResetDefinition are solving a problem - the dependency graph is normally evaluated just once and than all the instances are kept. With the Savepoint and ResetDefinition you can redefine certain graph leafs and those will be re-evaluated. The re-evaluation as well cascades to deps that depends on the one that is being reset.

  • Instance wrappers

Jira ID

[XX-XX]

Notes for your reviewers

// as to copy definition and but apply different wrappers
root.ContainerA.Dependency2.As(&root.ContainerA.Dependency1).Wrap(
   &root.Wrapper,
   plumber.WrapperFunc(func(s *Dep) *Dep { return s })
)
// localy wrap instance
root.ContainerA.Dependency2.InstanceErrorWrap(&root.Wrapper)
root.ContainerA.Dependency2.InstanceWrap(&root.Wrapper)
// Savepoint creates a restoration point
restore, err := plumber.SavePoint(c, &c.Greeting)
	assert.NilError(t, err)

	t.Run("redefining a cloned dep does not affect the source", func(t *testing.T) {
		// Reset both Greeting and its transitive dependent (Sub.Derived) on the clone so
		// they can be re-defined and re-resolved independently of the original container.
		if err := plumber.ResetDefinition(c, &c.Greeting); err != nil {
			t.Fatalf("ResetDefinition on clone failed: %v", err)
		}

		c.Greeting.Const("howdy")

		assert.Equal(t, "howdy", c.Greeting.Instance())
		assert.Equal(t, "howdy!", c.Sub.Derived.Instance())
	})

	t.Run("Restore point does not affect the source", func(t *testing.T) {
                // Restores to previous state
		restore()
		assert.Equal(t, "hello", c.Greeting.Instance())
		assert.Equal(t, "hello!", c.Sub.Derived.Instance())
	})

// ...

// Disables already defined wrapper
err = plumber.DisableWrapper(c, &c.GreetingWrapper)

@pavelsmejkal
pavelsmejkal requested a review from a team as a code owner May 28, 2026 09:37
@pavelsmejkal
pavelsmejkal requested a review from dundee May 28, 2026 09:51

@chladnefazole chladnefazole left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also store the examples somewhere, in readme or contributing or whatnot?

It's kind of abstract, I would like to see examples with something from stonehenge or a real use case, but it's interesting, possibly could help with the horrendous giant mocks I had to setup in Content before...

Comment thread .vscode/settings.json
Comment thread example/application_grpc.go
@pavelsmejkal

Copy link
Copy Markdown
Collaborator Author

Could you also store the examples somewhere, in readme or contributing or whatnot?

It's kind of abstract, I would like to see examples with something from stonehenge or a real use case, but it's interesting, possibly could help with the horrendous giant mocks I had to setup in Content before...

What for ? ... there are 3 examples of what was being added. There is a better documentation on the other PR, so you can approve that one and you will have it.

@chladnefazole

Copy link
Copy Markdown
Contributor

@pavelsmejkal Which other PR?

@pavelsmejkal

Copy link
Copy Markdown
Collaborator Author

@pavelsmejkal Which other PR?

#40

There are agent skills for each plumber area with explanation. once merged i will describe same way features introduced in this PR

@chladnefazole chladnefazole left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pavelsmejkal
pavelsmejkal merged commit 5ced1f7 into main Jun 11, 2026
9 checks passed
@pavelsmejkal
pavelsmejkal deleted the ps/wrappers branch June 11, 2026 14:13
@getoutreach-ci-1

Copy link
Copy Markdown

🎉 This PR is included in version 1.16.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants